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.
Auth::user()
works in the controller, but not in the Model. It returns null
.
The code is:
public function scopeOwned($query) {
$query->where('user_id', '=', Auth::user()->id);
}
I tried dd(Auth::user())
and it returns null
as well.
Any Idea?