我得到错误在php artisan route:list命令在laravel? [英] I get the error in php artisan route:list command in laravel?

查看:2123
本文介绍了我得到错误在php artisan route:list命令在laravel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 php artisan route:list 命令然后我得到这个错误

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

推荐答案

得到错误的原因是这段代码:

The reason you're getting the error is this piece of code:

Auth::user()->name;

当你运行 php artisan route:list 时,Laravel实例化所有控制器来检查,如果他们声明一个中间件 - 它通常是通过调用 middleware 方法。此时,没有用户会话,因此 Auth :: user()不会返回任何内容,这就是为什么尝试访问名称属性时出错的原因对非对象。

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.

这篇关于我得到错误在php artisan route:list命令在laravel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆