Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kirinyetbrian's avatar

ErrorException Attempt to read property "name" on null (View: resources/views/navigation-menu.blade.php)

i get the following error on navigtion-menu.blade.php

the debugger indicates that the error orginates from these lines

{{ Auth::user()->name }} {{ Auth::user()->email }}
0 likes
12 replies
tykus's avatar

In that case, you do not have an authenticated user.

I expect that you are most likely using a view component/partial which was intended for view(s) to be shown to authenticated users only? Since you own the view template (i.e. it is not in a vender sub-directory), you can wrap relevant parts in an @auth check

// resources/views/navigation-menu.blade.php

@auth
 {{ Auth::user()->name }} {{ Auth::user()->email }} 
@endauth
2 likes
tykus's avatar

Do you have Auth::user()->name on the forgot password page as well (separately to the navigation.blade.php template?

tykus's avatar

🤷‍♂️

Has the error changed from earlier; is it pointing to another view template?

I don't know your code...

tykus's avatar

Is this the navigation.blade.php? Where is the opening @auth directive?

tykus's avatar

Can you answer the second question? And properly format your code snippets?

tykus's avatar

There are references to Auth::user() everywhere in that view template, but nowhere are there @auth checks?

I expect that you are most likely using a view component/partial which was intended for view(s) to be shown to authenticated users only

I wasn't joking earlier...

tykus's avatar

Up to you. However, entire divs will not make sense if there is not authenticated user, so it'd make sense to identify these areas of the template and wrap them in the auth check.

tykus's avatar

👍 Mark it solved if you're all set

mrgroot's avatar

If you are using Jetstream, it uses Forty, so if you created user groups and these created with a seeder it does not add a group, if you want to quickly solve it, it is to create a record in team_user and add it to the created users.

claudiorigo's avatar

ErrorException, Attempt to read property "name" on null, {{ Auth::user()->name }}....I have a similar problem, the login is fine, it's just that when I leave the computer alone and come back, it throws me an error message Auth::user()->name, this must be because the session expired, but the query is I can control this? something that sends the user back to login instead of sending this error

tykus's avatar

@claudiorigo use the auth middleware on Routes that need an authenticated user (and ultimately that return view(s) that expect an authenticated user). Redirection to login will be automatic whenever the user navigates to such routes after the Session has expired.

Please or to participate in this conversation.