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

為{幸葍}努か 提交于 2019-12-23 01:54:11

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/34350726/i-get-the-error-in-php-artisan-routelist-command-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!