Search code examples
laravellaravel-3laravel-routing

Laravel 3 Query Strings


How can I get ? queries from url? input::all not works.

my route :

Route::get('category/(:any?)','category@index');

what I wanted to get is like :

http://url.com/category/examplecategory?list_as=grid&price_range=2

prinr_r of Input::all(). why can't I have list_as => grid and price_range => 2

Array ( [category/examplecategory] => )

my output should be :

Array ( [list_as] => "grid" , [price_range] => 2 [another_filter] => "another value"....)

Solution

  • You may try this

    parse_str(Request::getQueryString(), $getVars);
    
    // Use these as
    echo $getVars['list_as'];
    echo $getVars['price_range'];
    

    Here, Request::getQueryString() (it's method of symfony Request class) will return a query string and parse_str will build the array and will put it into $getVars.