mistre83's avatar

Route with parameters, the page cannot be found

Hi to all, in my web.php i have this simple route:

$app->get('test/{name}', 'ExampleController@test');

And the controller:

 public function test(Request $request)
    {
        dd($request->get('name'));
    }

I did tried to access this page in any way, and even i got "Sorry, the page you are looking for could not be found."

http://test-lumen.app/test
http://test-lumen.app/test?name=foo
http://test-lumen.app/test/?name=foo
http://test-lumen.app/test/?name\=foo

Sure, lumen is configured well and route without parameters works.

0 likes
2 replies
Indemnity83's avatar

Do this instead

public function test(Request $request, $name)
{
    dd($name);
}
jekinney's avatar

Your trying to pass data in your URL but request gets data from the request body. Not the same thing.

In your case, your not submitting data just a URL parameter. Once again not the same thing.

For test/{name} your URL should be /test/foo.

In your controller remove the request cases and put ($name)

dd($name) will = foo.

Keep in mind laravel uses pretty URL so it expects Params in the URL as a URL.

Also to keep things oop style might want to use $request->name ???

Please or to participate in this conversation.