Laravel 5登录后重定向到原始目的地

时间:2015-11-09 23:35:53

标签: php login laravel-5

我在laravel 5工作,登录时遇到了困难。

登录后,我希望我的页面按权限重定向。 如果access = 1则转到后端,如果access = 0,则返回欢迎页面,但我继续转到laravel的默认页面" home"而我无法改变。我不明白为什么。

public function postLogin() {

$email  = Request::input('email');
$password   = Hash::make(Request::input('password'));

//if (Auth::attempt(['email' => $email, 'password' => $password, 'acesso' => 1])) {

if (Auth::attempt(['email' => $email, 'password' => $password])) {
         return redirect()->intended('backend/dashboard.index')->with('message', 'Backend!');
    } elseif (Auth::attempt(['email'=> $email, 'password' => $password])) {
        return redirect()->intended('welcome')->with('message', 'Frontend!');
    } else {
        return view('auth/login')->with('message', 'error!');;
    }
}

路线:

// Authentication routes...
Route::get('auth/login', 'BackendControlador@getLogin');
Route::post('auth/login', 'BackendControlador@postLogin');

1 个答案:

答案 0 :(得分:0)

在Laravel 5中,AuthenticatesAndRegistersUsers特性将'/home'设置为postLogin函数中重定向到的默认路径。您可以通过设置redirectPath:

来覆盖它

在Http \ Auth \ AuthController.php中,添加:

//Replace 'path here' with the path you want to redirect to. Example: '/welcome'
protected $redirectPath = 'path here';

这是基于Laravel提供的AuthController的使用。在您的帖子中,我收集您已在控制器“BackendControlador”中创建了自己的postLogin方法,因此您可能需要在此控制器中添加该属性。