2015-05-24 29 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(); 
}