Laravel: Auth::user()->id trying to get a property of a non-object Laravel: Auth::user()->id trying to get a property of a non-object laravel laravel

Laravel: Auth::user()->id trying to get a property of a non-object


Now with laravel 4.2 it is easy to get user's id:

$userId = Auth::id();

that is all.

But to retrieve user's data other than id, you use:

$email = Auth::user()->email;

For more details, check security part of the documentation


If you are using Sentry check the logged in user with Sentry::getUser()->id. The error you get is that the Auth::user() returns NULL and it tries to get id from NULL hence the error trying to get a property from a non-object.


Do a Auth::check() before to be sure that you are well logged in :

if (Auth::check()){    // The user is logged in...}