laravel - Can't get session in controller constructor

后端 未结 8 1763
感动是毒
感动是毒 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:22

    I used Session in the construct using middleware, You can try, It would be helpful

    public function __construct()
    {
        $this->middleware('PM');
    
        $this->middleware(function ($request, $next){
            $school_id = Session::get('school_id');
    
    
            return $next($request);
        });
    }
    

提交回复
热议问题