laravel 5.2 取 Auth::user() 的值一直为NULL

306 查看

因为 laravel 5.2 更新了路由策略.........

所以所有路由都应该写在中间件web的下面

 Route::group(['middleware' => 'web'], function () {
     // your routes
 });

当然也可以把web中间件放到全局的中间件里面去 ,在app/Http/Kernel.php文件中,然后把web中间件删掉

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \App\Http\Middleware\EncryptCookies::class,
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\VerifyCsrfToken::class
];