Problems with Auth::user()

Posted 4 years ago by zefman

Hello everyone.

So today I have ran composer update to bring a project up to the latest version of Laravel 5, almost everything is fine, but I am having issues with Auth::user() after updating.

In a number of places in the app I use Auth::user() to return the currently logged in user, the problem is, after this most recent update whenever I then go to try and load relations on the returned user object I get an error like:

Call to undefined method Illuminate\Database\Query\Builder::comments()

For example the following code causes this error:

$user = Auth:;user();
$user->load( 'profile.media', 'roles' );

likewise does this:

$user = \Auth::user();
$comments = $user->comments;

This was all working fine before so I am not sure whats wrong. Interestingly if I use the id from the user returned by Auth to again find the user like:

$user = User::find( Auth::user()->id );
$comments = $user->comments;

It works. Anyone got any ideas?


Please sign in or create an account to participate in this conversation.