Auth::user() returns null in Laravel 5.2

前端 未结 4 802

I have searched and found various results like these: auth()->user() is null in Laravel 5.2 and Auth::user() returns null

But, mine is still not working.

4条回答
  •  时光取名叫无心
    2021-01-06 10:50

    I have a similar problem with Laravel 5.2, Try to change Auth::user()->id to Auth::id()

    public function scopeOwned($query) {
        $query->where('user_id', '=', Auth::id());
    }
    

    It's worked for me!

提交回复
热议问题