Laravel 8: error when routing a GET to any view and receiving a error "Trying to get property 'user_id' of non-object"

1.5k views Asked by At

I've created a new Laravel 8 app with Jetstream and Livewire. When I make a GET request to any view an ErrorException is launched with message

Trying to get property 'user_id' of non-object

on navigation-dropdown.blade.php which is automatically generated by Jetstream\Livewire. I've looked for this user_id and didn't found on any part of the code.

2

There are 2 answers

0
A. Khaled On

Check that if user has team in the blade view.

resources/views/navigation-dropdown.blade.php

In line 61:

- @if (Laravel\Jetstream\Jetstream::hasTeamFeatures())
+ @if (Laravel\Jetstream\Jetstream::hasTeamFeatures() && Auth::user()->current_team_id)

In line 162:

- @if (Laravel\Jetstream\Jetstream::hasTeamFeatures())
+ @if (Laravel\Jetstream\Jetstream::hasTeamFeatures() && Auth::user()->current_team_id)
0
ob1y2k On

Fortify adds it's own auth routes, but old routes in config/auth.php will still be used (in my case)

Simple solution is to comment out all routes in config/auth.php (if using jetstream with fortify)

and run :

php artisan route:cache

this will make sure that auth routes use fortify actions, so each new account you create will have team created