douding7189 2017-02-14 07:05
浏览 83
已采纳

Laravel 5.2:失败后将用户重定向到登录页面

How should i redirect user to login page after a failed login? i tried in AuthController :

  protected $redirectTo ='/login';
protected $loginView = 'auth.login_register_form';
protected $loginPath = '/login';

but user does not redirected to /login page , he get redirected back to the page he was in before
of curse there is a method in AuthenticateUser.php that serve as login fails method:

protected function sendFailedLoginResponse(Request $request)
{
    return redirect()->back()
        ->withInput($request->only($this->loginUsername(), 'remember'))
        ->withErrors([
            $this->loginUsername() => $this->getFailedLoginMessage(),
        ]);
}

but i'm not allowed to edit this method . this is one of laravel core files.

  • 写回答

1条回答 默认 最新

  • doujuegai8830 2017-02-14 07:08
    关注

    In your controller you have to return him redirect (not just assign path to variable), for example

    return redirect('/login');
    

    If it's form with filled inputs you can do something like

    return redirect('/login')->withInput();
    

    In your example

    protected function sendFailedLoginResponse(Request $request)
    {
        return redirect('/login')
            ->withInput($request->only($this->loginUsername(), 'remember'))
            ->withErrors([
                $this->loginUsername() => $this->getFailedLoginMessage(),
            ]);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器