Laravel 5 route parameters not send

2019-06-19 22:48发布

问题:

With Laravel 5 I'm not able to setup get route parameters.

My route is setup like this:

Route::get('test', 'TestController@test');

And my TestController looks like this:

public function test(Request $request)
{
    var_dump($request->input('foo'));
}

When I browse to that route with a parameter

/test?foo=bar

the result is NULL.

Can anybody tell me what I'm doing wrong?

The Input::get('foo') syntax doesn't work either (and is not even mentioned in the documentation for L5).

Update:

I'm using Apache as webserver.

I have also tried

$request->get('foo')

and a route like this

Route::get('test/{foo?}', 'TestController@test');

with the same URL and still get null.

Update 2:

The documentation of L5 gives examples for routes like this:

/test/bar

instead of

/test?foo=bar

In L4 it was possible to browse to routes with GET like

/test?foo=bar&id=2&user=admin

or changing the order

/test?id=2&user=admin&foo=bar

with one and the same route

Route::get('test', 'TestController@test');

and all you had to do was get it with

Input::get('user')

But with L5 it wouldn't be possible to change the order of parameters when you have to use slashes in the routes like

Route::get('test/{id}/{user}/{foo}', 'TestController@test');

Is this really a big downgrade for routes in L5?

回答1:

The problem was the .htaccess file, I used an edited one where the parameters didn't get send.

With the default .htaccess file that comes with the Framework everything works!



回答2:

Would you try this?

use Request;

public function test(Request $request)
{
    var_dump($request->get('foo'));
}


回答3:

In laravel 5 you can put a param into controller method like this:

public function test(Request $request, $foo) { }

with route - Route::get('test/{foo}', 'TestController@test');`