Laravel 5 route parameters not sent

With Laravel 5, I cannot configure route parameters.

My route is configured as follows:

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

And my TestController looks like this:

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

When I view this route with the parameter

 /test?foo=bar 

the result is NULL.

Can anyone tell me what I'm doing wrong?

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

Update:

I use Apache as a web server.

I also tried

 $request->get('foo') 

and a route like this

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

with the same url and still gets null.

Update 2:

The L5 documentation provides examples of such routes:

 /test/bar 

instead

 /test?foo=bar 

In L4, you could find routes using GET, for example

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

or reordering

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

with the same route

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

and all you had to do was get it using

 Input::get('user') 

But with L5 it would be impossible to change the order of parameters when you need to use slashes in routes, for example

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

Is this really a big drop for routes in L5?

+6
source share
3 answers

The problem was with the .htaccess file, I used an edited file in which the parameters did not work.

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

+1
source

Would you try this?

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

In laravel 5, you can put a parameter in a controller method as follows:

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

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

0
source

Source: https://habr.com/ru/post/985438/


All Articles