Laravel 5.0 - change redirect when login fails

时间:2015-10-14 04:31:17

标签: php laravel authentication redirect controller

I'm using Laravel 5.0 built-in authentication controllers, and in the AuthController I have 2 variables:

protected $redirectTo = '/';
protected $redirectAfterLogout = '/';

Is there any variable which would redirect to a specific page if and only if the login failed? If not, how should I do it?

2 个答案:

答案 0 :(得分:-1)

请在控制器中插入波纹管方法

public function authenticate(Request $request)
    {
        if (Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')]))
        {
            return redirect()->intended('dashboard');
        } else {
           return redirect('your-path-to-redirect');
        }
    }

答案 1 :(得分:-1)

我知道这个问题已经过时但我会发表我的答案,因为它对将来的某些人有用。

当身份验证失败时,默认情况下会将其重定向到 / auth / login URI。如果你想修改它,只需在AuthController上添加 loginPath属性并设置你自己的路径:

protected $loginPath = '/your-path';

您可以在Authentication Laravel Docs

中找到更多信息

希望这有帮助!