laravel - Can't get session in controller constructor

后端 未结 8 1756
感动是毒
感动是毒 2020-12-05 19:02

In new laravel I can\'t get session in constructor. Why?

public function __construct()
{
    dd(Session::all()); //this is empty array
}

a

8条回答
  •  再見小時候
    2020-12-05 19:24

    As of Laravel 6.18.1, add these to $middleware array in the kernel.php

    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    

    And it should work.

提交回复
热议问题