Laravel 5 : [调用非对象的成员函数 getAction()
Laravel 5 : [Call to a member function getAction() on a non-object
在我的控制器中,我有
Route::getCurrentRoute()->getAction()['as']
在浏览器中一切正常,但只要我输入
php artisan route:list
在终端我有这个异常
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function getAction() on a non-object
如果我评论这一行一切正常。
很明显不是吗?
在浏览器中获取当前路线将return当前访问的路线。在终端中,您没有这样的请求。 Laravel询问访问的是什么路由时,return为null。在调用 getAction.
之前,您必须检查 return 值
您可以使用此代码...
if(!App::runningInConsole()){
Route::getCurrentRoute()->getAction()['as'];
}
当您 运行 artisan 命令时,它不会出错。
在我的控制器中,我有
Route::getCurrentRoute()->getAction()['as']
在浏览器中一切正常,但只要我输入
php artisan route:list
在终端我有这个异常
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function getAction() on a non-object
如果我评论这一行一切正常。
很明显不是吗?
在浏览器中获取当前路线将return当前访问的路线。在终端中,您没有这样的请求。 Laravel询问访问的是什么路由时,return为null。在调用 getAction.
之前,您必须检查 return 值您可以使用此代码...
if(!App::runningInConsole()){
Route::getCurrentRoute()->getAction()['as'];
}
当您 运行 artisan 命令时,它不会出错。