I get the error in php artisan route:list command in laravel?

- 1 answer

Ad

When I run php artisan route:list command then i am getting this error

Error

Ad

Answer

Ad

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.

Ad
source: stackoverflow.com
Ad