laravel获取不到session

session可以存储但是无法获取 修改 app/http/kernel.php文件

protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\Session\Middleware\AuthenticateSession::class, #这句话本来是注释掉的,开启就可以了!
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

'api' => [
'throttle:60,1',
'bindings',
],
];

如果实在构造方法中获取不到session

$this->middleware(function() {
            $this->admin = session('admin');
            $this->isLogin = $this->admin == null ? false : true;
        });

  

 
posted @ 2020-06-29 09:11  王的孤傲  阅读(1213)  评论(0编辑  收藏  举报