Search code examples
laravellaravel-routinglaravel-5.3

Basic route with paramter failing in Laravel 5.3


I have a basically fresh install of Laravel 5.3 and I wanted to look into passing parameters to a route. I literally copied this from Laravel Docs,,

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

When I try to access the route:

http://testsite.dev/user/1

I should see

User 1

Instead I get this:

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

This does not happen with routes without parameters.


Solution

  • Make sure that Laravel installer didn't create a sub directory. You can always check by just visiting http://testsite.dev/ and making sure you get the Laravel Welcome Page. That's the first step to resolving your issue. I copied your code into a fresh install and it worked, I believe your problem lies with the installation.