在Laravel 5.3中,参数失败的基本路线

时间:2016-12-16 22:25:50

标签: laravel laravel-routing laravel-5.3

我有一个基本上全新安装的Laravel 5.3,我想查看将参数传递给路线。我真的从Laravel Docs中复制了这个,

Route::get('user/{id}', function ($id) {
    return 'User '.$id;
});

当我尝试访问路线时:

http://testsite.dev/user/1

我应该看到

User 1

相反,我得到了这个:

Sorry, the page you are looking for could not be found.

NotFoundHttpException in RouteCollection.php line 161:

    1. in RouteCollection.php line 161
    2. at RouteCollection->match(object(Request)) in Router.php line 755
    3. at Router->findRoute(object(Request)) in Router.php line 610
    4. at Router->dispatchToRoute(object(Request)) in Router.php line 596
    5. at Router->dispatch(object(Request)) in Kernel.php line 268
    6. at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
    7. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
    8. at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
    9. at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
    10. at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
    11. at Pipeline->then(object(Closure)) in Kernel.php line 150
    12. at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
    13. at Kernel->handle(object(Request)) in index.php line 54

没有参数的路线不会发生这种情况。

1 个答案:

答案 0 :(得分:0)

确保Laravel安装程序没有创建子目录。您只需访问http://testsite.dev/并确保获得Laravel欢迎页面即可查看。这是解决问题的第一步。我将您的代码复制到一个全新的安装中并且它有效,我相信您的问题在于安装。