ekta singh
ekta singh

Reputation: 138

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

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

Error

Upvotes: 1

Views: 3416

Answers (1)

jedrzej.kurylo
jedrzej.kurylo

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

Related Questions