我可以帮您将默认的Laravel路由从/auth/login更改为只有/login,同样也可以对注册进行相应的修改。
以下是我的路由信息:
现在问题来了,当用户尝试访问一个受保护的区域时,Authentication 类起作用,将未经身份验证的用户重定向回/auth/login而非仅仅是/login。
我曾尝试通过以下方式在我的AuthController中设置$loginPath来解决这个问题:
以下是我的路由信息:
Route::get('login', ['as' => 'getLogin', 'uses' => 'Auth\AuthController@getLogin']);
Route::post('login', ['as' => 'postLogin', 'uses' => 'Auth\AuthController@postLogin']);
Route::get('logout', ['as' => 'getLogout', 'uses' => 'Auth\AuthController@getLogout']);
Route::get('register', ['as' => 'getRegister', 'uses' => 'Auth\AuthController@getRegister']);
Route::post('register', ['as' => 'postRegister', 'uses' => 'Auth\AuthController@postRegister']);
现在问题来了,当用户尝试访问一个受保护的区域时,Authentication 类起作用,将未经身份验证的用户重定向回/auth/login而非仅仅是/login。
我曾尝试通过以下方式在我的AuthController中设置$loginPath来解决这个问题:
protected $loginPath = '/login';
但是似乎 $loginPath 只用于登录失败的情况,而不是像在 AuthenticateUsers Class 中记录的认证失败的情况。
我成功地从以下位置更改了 Authenticate Class 中的 redirectURL:
return redirect()->guest('auth/login');
转换为:
return redirect()->guest('login');
这解决了问题,但我想在我的AuthController
中设置一个属性,就像这样:
protected $redirectIfMiddlewareBlocks = '/login';
为此,我在认证类中检查一个属性是否存在,该属性是我在AuthController中设置的:
return redirect()->guest(property_exists($this, 'redirectIfMiddlewareBlocks') ? $this->redirectIfMiddlewareBlocks : '/shouldnotbeused');
然而我得到了/shouldnotbeused的url,而不是在我的AuthController中设置的redirectIfMiddlewareBlocks属性。
我该如何正确地设置登录路由的路径呢?
redirect()->guest('login')
。 - andrewtweber