在Laravel 5.2中auth()-> user()为null
问题描述:
我只是将作曲家更新为Laravel 5.2,无法查看受密码保护的页面.基本上下面的代码行不起作用.
I just update the composer to Laravel 5.2 and not able to view password protected pages. Basically below line of code is not working.
auth()->user()
有人可以建议为什么这不起作用吗?
Can somebody suggest why this is not working ?
答
确保所有需要会话(Auth使用的会话)的路由都在'web'中间件组的后面.
Make sure any routes that require sessions (which Auth uses) are behind the 'web' middleware group.
Route::group(['middleware' => 'web'], function () {
// your routes
});
这是5.2的新更改.默认情况下,路由未应用此中间件堆栈. Web中间件组设置了会话存储,cookie和csrf保护.
This is a change that is new to 5.2. By default routes do not have this middleware stack applied. The web middleware group sets the session store, cookies, and csrf protection.