Support the ongoing development of Laravel.io →
Requests Input Forms

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,

View:


{ 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>
    </select>
    {{ Form::submit('Send') }}
{{ Form::close() }}

Route:

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

When i submit the form it redirect me to

search/%7Bcategory%7D/%7Bterm%7D?term=asdasd&category=auto

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

Last updated 3 years ago.
0

You can not change the action url of the form while filling it (you can with Javascript but that would be verycomplicated).
Instead take the submitted parameters with Input::get('parametername').

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

SearchController

function search()//no parameters from route
{
$category = Input::get('category');
echo $category;
$term = Input::get('term');
echo $term;
}
0

Hello

No way javascript :p

finally i did a function red_search() that redirect to /search/{category}/{term}

public function red_search()
	{
		$url=Request::all();
		
		return redirect('search/'.$url['category'].'/'.$url['term']);
	}

thank you ;)

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

NearRiv nearriv Joined 28 Mar 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.