Reputation: 3239
I'm trying to get username from view using:
Auth::user()->name
and I'm getting
Trying to get property of non-object
because Auth::user()
is NULL. How is this possible? The navbar laravel generates uses the same and it works there.
EDIT: It seems that I can't even get the auth user from the Controller.
Auth::guard('admin')->check(); //true
Auth::user(); //null
Any ideas?
Upvotes: 4
Views: 2057
Reputation: 3239
Well I figured it out again, since I used a custom guard, I actually needed to use:
Auth::guard('admin')->user()->name;
Upvotes: 4
Reputation: 1421
Make sure that you are logged in before trying to access a view with {{Auth::user()->name}}
.
Upvotes: 1
Reputation: 3266
You can also use global auth()
from view.
{{auth()->user()->name}}
Upvotes: 2