protected $middleware = [
\App\Http\Middleware\Syspoint::class,
]
use Session;
class Syspoint
{
echo \Session::get('syspoint');
}
我有一个中间件需要在每次页面请求时运行,该中间件包含会话。
我放在里面protected $middleware
,但全局中间件无法获取会话。
您正在调用 Session 但它尚未启动。
如果您的中间件中需要 Session,则必须将其放入属性中protected $middlewareGroups
在钥匙下web
在调用 StartSession 之后,即:
protected $middlewareGroups
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\App\Http\Middleware\Syspoint::class,
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)