Laravel 5.4 : Get logged in user id inside __construct()

后端 未结 3 1749
有刺的猬
有刺的猬 2020-12-03 23:59

I am trying to access Auth::user()->id; inside constructor but it always return the error Trying to get property of non-object. I study in t

3条回答
  •  抹茶落季
    2020-12-04 00:30

    Try this:

    public function __construct(){
        $this->middleware(function ($request, $next) {
            $induction_status = TrainingStatusRecord::where('user_id',Auth::user()->id)->where('training','=','induction')->get();
        }
        View::share('induction_status',$induction_status);
    }
    

提交回复
热议问题