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

因为 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
];
    原文作者:alonehover
    原文地址: https://segmentfault.com/a/1190000006053920
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞