Reputation: 138
When I run php artisan route:list
command then i am getting this error
Upvotes: 1
Views: 3416
Reputation: 40909
The reason you're getting the error is this piece of code:
Auth::user()->name;
in your CategoryController's constructor.
When you run php artisan route:list, Laravel instantiates all controllers to check, if they declare a middleware - it's usually done in constructor by a call to middleware() method. At this point, there is no user session, therefore Auth::user() won't return anything, that's why you're getting an error trying to access name property on non-object.
You shouldn't access user object in the constructor, do that in action methods.
Upvotes: 4