Iliyass Hamza Iliyass Hamza - 6 months ago 18
PHP Question

How To Pass GET Parameters To Laravel From With GET Method ?

i'm stuck at this very basic form, that i could not accomplish, which i want to build a search form with an text input, and two select controls, with a route that accept 3 parameters, the problem that when the i submit the form, it map the parameters with the question mark, not the Laravel way,


{{ Form::open(['route' => 'search', 'method' => 'GET'])}}
<input type="text" name="term"/>
<select name="category" id="">
<option value="auto">Auto</option>
<option value="moto">Moto</option>
{{ Form::submit('Send') }}
{{ Form::close() }}


Route::get('/search/{category}/{term}', ['as' => 'search', 'uses' => 'SearchController@search']);

When i submit the form it redirect me to


How can i pass these paramters to my route with the Laravel way, and without Javascript ! :D


The simplest way is just to accept the incoming request, and pull out the variables you want in the Controller:

Route::get('search', ['as' => 'search', 'uses' => 'SearchController@search']);

and then in SearchController@search:

class SearchController extends BaseController {

    public function search()
        $category = Input::get('category', 'default category');
        $term = Input::get('term', false);

        // do things with them...

Usefully, you can set defaults in Input::get() in case nothing is passed to your Controller's action.

As joe_archer says, it's not necessary to put these terms into the URL, and it might be better as a POST (in which case you should update your call to Form::open() and also your search route in routes.php - Input::get() remains the same)