Laravel 5 : [Call to a member function getAction() on a non-object

限于喜欢 提交于 2019-12-20 03:10:12

问题


In my Controller, I have

Route::getCurrentRoute()->getAction()['as']

Everything works well in the browser but as soon as I type

php artisan route:list

in the terminal I have this exception

[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function getAction() on a non-object

If I comment this line everything works well.


回答1:


Seems obvious doesn't it?

Get current route in a browser will return the currently visited route. In the terminal you do not have such a request. Laravel will return null when asking what route is visited. You would have to check for the return value before calling getAction.




回答2:


You can use this code...

if(!App::runningInConsole()){
    Route::getCurrentRoute()->getAction()['as'];
}

when you run artisan command it will not get an error.



来源:https://stackoverflow.com/questions/30826725/laravel-5-call-to-a-member-function-getaction-on-a-non-object

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