2017-02-26 122 views
0

我下面就TutorialsPoint的Laravel教程,我現在在基本的路由部分,但我似乎無法得到第一功能的工作(在我app/Http/routes.php文件下面的代碼Laravel基本的路由不工作

Route::get('ID/{id}',function($id){ 
    echo 'ID: '.$id; 
}); 

當我在URL輸入http://localhost:8000/ID/5我得到下面的錯誤

Sorry, the page you are looking for could not be found. 
NotFoundHttpException in RouteCollection.php line 161: 
in RouteCollection.php line 161 
at RouteCollection->match(object(Request)) in Router.php line 533 
at Router->findRoute(object(Request)) in Router.php line 512 
at Router->dispatchToRoute(object(Request)) in Router.php line 498 
at Router->dispatch(object(Request)) in Kernel.php line 174 
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 30 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30 
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TransformsRequest.php line 30 
at TransformsRequest->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ValidatePostSize.php line 27 
at ValidatePostSize->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46 
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 148 
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 53 
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 102 
at Pipeline->then(object(Closure)) in Kernel.php line 149 
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116 
at Kernel->handle(object(Request)) in index.php line 53 

我失去的東西,我沒有做?

注意:我的app/Http文件夾中沒有route.php,我自己添加了它。

如果我缺少可能有幫助的信息,請告訴我,以便我可以把它們。

+0

我在另一個問題,我應該使用PHP的工匠服務,但也沒有工作 –

回答

2

您正在使用的教程基於Laravel 5.1,如果您在項目初始化過程中未指定版本,則您的Laravel項目應使用最新版本,即5.4。 (你可以在你的Laravel項目文件夾執行命令 php artisan --version檢查正在使用的版本。

但問題是,該路由機制是在5.3版本改變,因此路由信息現在位於文件夾「路線」(橫跨三個文件拆分:網絡,API控制檯)。(請參閱https://laravel.com/docs/5.4/routing獲取更多信息)

要使用你的路線,你只需要你的榜樣路由添加到web.php文件

希望對您有所幫助!

此致敬禮
Tek

+0

這是真的,我沒有注意到laravel版本的差異,我使用5.4。感謝您的鏈接 –