I have my route set as
Route::any('/{brand?}/{type?}/{city?}', 'SearchController@index')->name('search');
I want to send from my controller query strings (Form GET params)
After searching I ended up with this but it does not work properly
return redirect()->route('search', [$brand->name, $type->name, 'search_model_from' => $request->search_model_from, 'search_model_to' => $request->search_model_to]);
which returns back
localhost:8000/toyota/avalon/2018?search_model_to=2019
I want to return
localhost:8000/toyota/avalon/?search_model_from=2018&search_model_to=2019
What I am trying to achieve in general is SEO friendly search functionality
2
Answers
Maybe you should try to assign city as null like that :
I’m not sure but this could happen because you have defined 3 optional parameters in the route and as you are sending just two of them, this might takes the next (in this case ‘search_model_from’) as the third parameter for url.
Maybe if you cast and set a default value to the optional parameters in your Controller, you won’t have that trouble, like this: