无法访问Laravel app \ Exceptions \ Handler.php中的会话 [英] Unable to access sessions in Laravel app\Exceptions\Handler.php
问题描述
我试图基于用户登录显示404页面,为此我试图从会话中获取登录的用户ID.
I'm trying to display 404 page based upon user login, for which I'm trying to get the logged in user id from sessions.
但是会话 session()-> all()
总是返回空数组,还返回 auth()-> id();
& Auth :: id();
也是空值.
But session session()->all()
always returns empty array and also auth()->id();
& Auth::id();
are also empty value.
推荐答案
这是因为在 app/Http/Kernel.php
中,受保护的$ middleware
数组没有会话的中间件.
That's because in app/Http/Kernel.php
the protected $middleware
array doesn't have the middleware for the session.
您可以做的是将 \ Illuminate \ Session \ Middleware \ StartSession :: class
中间件从 web
middlware组移动到全局 $中间件
数组.
What you can do is to move the \Illuminate\Session\Middleware\StartSession::class,
middleware from the web
middlware group to the global $middleware
array.
这篇关于无法访问Laravel app \ Exceptions \ Handler.php中的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!