使用Laravel 5无法保持Auth :: login

时间:2016-02-23 23:42:22

标签: laravel authentication

我尝试在Controller或路由中手动登录用户。这适用于页面范围,但它不会持续存在。

这是我的代码:

Route::get('check', function (){
    if (Auth::loginUsingId(1)) { // User #1 is existing in the DB
      return redirect()->intended('/check2');
    }
});

Route::get('check2', function (){
    dd(Auth::user());
});

我得到了:我的/ check2页面上的null

有人能给我一个快速提示吗?

PS:我测试了默认的Auth Laravel系统并且它可以工作。

非常感谢!

1 个答案:

答案 0 :(得分:1)

问题很简单。在Laravel 5.2上,您需要将所有相关路由包装在中间件“web”中,以便使用Authentification。

谢谢大家。

相关问题