Reputation: 45
I need some help on a topic that is making me crazy on Laravel 5.2
I have the following routes.php, which I have reduced to the minimum :
use Illuminate\Http\Request;
/**
* Category Page
*/
Route::get('/category/test/', function()
{
dd("I'm in !");
dd(Input::all());
$page = Input::get('page');
if(isset($page)){
dd($page);
}
}
When I call the following url : http://192.168.99.100/category/test?page=55, I would expect to get the parameter page in Input or Request but however it is always empty. The following code just displays "I'm in !" but nothing else.
Can you help me understanding what is wrong in here ? I previously used controllers and Request parameters but it was also empty, thus this simple test. Note that post requests are working fine.
Thanks !
Upvotes: 2
Views: 1605
Reputation: 45
I finally found it out !
That was a problem in my nginx configuration, that prevented php variable QUERY_STRING to be correctly set up and Laravel is basing on this variable to retrieve the data.
For more information, see https://serverfault.com/questions/231578/nginx-php-fpm-where-are-my-get-params/362924#362924
Thaks for your answers anyway !
Upvotes: 2
Reputation: 4022
You can use both , actually there is no error in your code except if you missed the use statement for Input
facade.
use Illuminate\Http\Request;
/**
* Category Page
*/
Route::get('/category/test/', function()
{
dd(Input::all());
dd("I'm in !");
$page = Input::get('page');
if(isset($page)){
dd($page);
}
}
So question is why you are getting nothing! because the route is GET request so if you post/update/patch anything to it you will get methodNotAllowed exception. Now just goto your browser and type http://whateverdomain/category/test/?page=atiq&have=fun
and yes now there is something.........
Route::get('/category/test/', function(Request $request)
{
$input=$request->All();
dd($input);
$page = request->get('page');
if(isset($page)){
dd($page, request->get('have'));
}
}
Upvotes: 1
Reputation: 1383
because you didn't told function to expect request
it shall be
Route::get('/category/test/', function(Request $Request)
{
$input=$Request->All();
dd($input);
// usage $input['query'];
$page = Input::get('page');
if(isset($page)){
dd($page);
}
}
Upvotes: 0