在Laravel 5.2中auth()-> user()为null [英] auth()->user() is null in Laravel 5.2
本文介绍了在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.
这篇关于在Laravel 5.2中auth()-> user()为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文