如何更改 Laravel 5.2 更改登录路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40821648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change Laravel 5.2 change login route?
提问by sandip kakade
Hello I am using Laravel 5.2 version. I installed the laravel project via composer. After that I use command "php artisan make:auth"for create auth. After created auth route is generated for example "http://localhost:8000/login". Now I don't want this route I want to set different route for example "http://localhost:8000/super/admin". So How can I change the "http://localhost:8000/login"to "http://localhost:8000/super/admin". And when auth generated that time /registerroute is create so that route i want to remove "http://localhost:8000/register"route. Please suggest me how to do this. Thanks in advance.
您好,我使用的是 Laravel 5.2 版本。我通过composer安装了laravel项目。之后我使用命令“php artisan make:auth”来创建身份验证。在创建身份验证路由后生成例如“ http://localhost:8000/login”。现在我不想要这条路线,我想设置不同的路线,例如“ http://localhost:8000/super/admin”。那么如何将“ http://localhost:8000/login”更改为“ http://localhost:8000/super/admin”。当 auth 生成那个时间/register路由被创建时,我想删除“ http:“路线。请建议我如何做到这一点。提前致谢。
回答by prateekkathal
Follow these simple steps
按照这些简单的步骤
If you have Route::auth()
in your routes.php
, then please remove that line.
如果你有Route::auth()
你的routes.php
,那么请删除了这一行。
Now add the following lines to your routes.php
现在将以下行添加到您的 routes.php
Route::get('super/admin', 'Auth\AuthController@getLogin')->name('auth.login.get');
Route::post('super/admin', 'Auth\AuthController@postLogin')->name('auth.login.post');
Route::get('super/admin/logout', 'Auth\AuthController@getLogout')->name('auth.logout.get');
Then go to login.blade.php
(most probably in resources->views->auth)
然后去login.blade.php
(很可能在resources->views->auth)
And change the form action to {{ route('auth.login.post') }}
, like this...
并将表单操作更改为{{ route('auth.login.post') }}
,就像这样......
<form action="{{ route('auth.login.post') }}" method="post">
Hope this answers everything :)
希望这能回答一切:)
回答by Md. Abu Taleb
In App\Http\Controllers\Auth\LoginController
- define a fuction named showLoginForm() as:
在App\Http\Controllers\Auth\LoginController
- 定义一个名为 showLoginForm() 的函数为:
public function showLoginForm()
{
$view = property_exists($this, 'loginView')
? $this->loginView : 'auth.authenticate';
if (view()->exists($view)) {
return view($view);
}
return view('auth.login');
}
It overrides the function showLoginForm defined in the trait Illuminate\Foundation\Auth\AuthenticatesUsers.
它覆盖了 trait 中定义的函数 showLoginForm Illuminate\Foundation\Auth\AuthenticatesUsers.
Note: In Laravel 5.3 the function name is changed from getLogin to showLoginForm.
For details gotoIlluminate\Foundation\Auth\AuthenticatesUsers.
注意:在 Laravel 5.3 中,函数名称从 getLogin 更改为 showLoginForm。
详情请到Illuminate\Foundation\Auth\AuthenticatesUsers.
回答by Miguel Nascimento
In the routes file, instead of using the default Route::auth()
, you have to register the routes yourself.
在路由文件中,Route::auth()
您必须自己注册路由,而不是使用默认值。
My advice would be to run php artisan route:list
. This will show you the default routes and their respective controllers (and methods). Then, remove Route::auth()
and implement the routes you want manually.
我的建议是跑php artisan route:list
。这将显示默认路由及其各自的控制器(和方法)。然后,Route::auth()
手动删除并实施您想要的路由。
So for example, if you want to change to login URL, you'd have to define it as:
Route::get('super/admin', 'App\Http\Controllers\Auth\AuthController@showLoginForm');
例如,如果要更改为登录 URL,则必须将其定义为:
Route::get('super/admin', 'App\Http\Controllers\Auth\AuthController@showLoginForm');
Do this for all the routes you want to replace. By removing Route::auth()
, you're removing the register route.
对要替换的所有路由执行此操作。通过删除Route::auth()
,您将删除注册路由。