登录失败后如何将用户重定向到登录页面?
我试过AuthController
:
protected $redirectTo ='/login';
protected $loginView = 'auth.login_register_form';
protected $loginPath = '/login';
但是用户没有重定向到/login
页面,他被重定向回到他之前的页面
诅咒AuthenticateUser.php
中有一个方法用作登录失败方法:
protected function sendFailedLoginResponse(Request $request)
{
return redirect()->back()
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors([
$this->loginUsername() => $this->getFailedLoginMessage(),
]);
}
但我不允许编辑此方法。这是laravel核心文件之一。
答案 0 :(得分:1)
在您的控制器中,您必须返回重定向(而不仅仅是指定变量的路径),例如
return redirect('/login');
如果它的填充输入形式可以执行类似
的操作return redirect('/login')->withInput();
在你的例子中
protected function sendFailedLoginResponse(Request $request)
{
return redirect('/login')
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors([
$this->loginUsername() => $this->getFailedLoginMessage(),
]);
}