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

前端 未结 2 1172
自闭症患者
自闭症患者 2021-01-22 20:14

In my Controller, I have

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

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



        
相关标签:
2条回答
  • 2021-01-22 20:25

    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.

    0 讨论(0)
  • 2021-01-22 20:35

    You can use this code...

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

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

    0 讨论(0)
提交回复
热议问题