2015-05-24 52 views
1

我使用Laravel 5并注意到每当我通过cmd执行php artisan route:list命令时都会发生奇怪的事情。当使用route时,Laravel getPath()无法识别:列表

这是给我的一个错误: [Symfony\Component\Debug\Exception\FatalErrorException] Call to a member function getPath() on a non-object

的代码,它指的是这样的: Route::getCurrentRoute()->getPath()

但是,当我转储代码,没有错误被抛出,这是正确的显示当前路线。

运行php artisan serve时也没问题。使用php artisan route:list命令时发生错误。 Route::getCurrentRoute()->getUri()

任何人都知道这里发生了什么? 非常感谢!

+0

哪个文件引发动作?你需要给它更多的信息。 – itachi

回答

1

错误发生,因为当您在控制台中Route::getCurrentRoute()返回null值。如果您在浏览器中,它将返回当前路线。对此的一个解决方案是检索当前路由是否为空,然后检索其某些属性:

$currentRoute = Route::getCurrentRoute(); 

if ($currentRoute) 
{ 
    $path = $currentRoute->>getPath(); 
}