我正在关注TutorialsPoint上的Laravel教程,我现在处于基本路由部分,但是我似乎无法使用第一个函数(我app/Http/routes.php
文件中的下面的代码
Route::get('ID/{id}',function($id){
echo 'ID: '.$id;
});
当我输入网址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
我错过了一些我没做过的事情吗?
注意:我的route.php
文件夹中没有app/Http
,我自己添加了它。
如果我遗漏了可能有用的信息,请告诉我,我可以把它们放进去。
答案 0 :(得分:2)
您使用的教程基于Laravel 5.1,如果您在项目初始化过程中未指定版本,则Laravel项目应使用最新版本,即5.4。 (您可以通过执行命令检查您正在使用的版本
Laravel项目文件夹中的php artisan --version
。
问题在于,路由机制在版本5.3中已更改,因此路由信息现在位于文件夹" routes" (分为三个文件:web,api,console)。 (有关更多信息,请参阅https://laravel.com/docs/5.4/routing)
要使用您的路线,您只需将示例路线添加到web.php文件。
希望有所帮助!
最好的问候 TEK