Reputation: 451
I'd like to set up some nice URL for my website but my issue is that my GET parameters are not all always filled.
For instance I can have all these different parameters:
?brand=BMW&model=i8+m4&location=USA
?brand=BMW&location=USA
?brand=BMW+Audi
However I'm not too sure if I should create a route for all the different scenarios I could have or if there is any other way to have some nice URL?
I'm thinking of what it could look like:
/brand/BMW+Audi/location/USA/model/i8
?
But if I have to create a route for every scenarios it could become very long!
Route::get(/brand/{brand})
Route::get(/brand/{brand}/location/{location})
Route::get(/brand/{brand}/model/{model}/location/{location})
Route::GET(/location/{location})...
Otherwise I can also create some dynamic parameters such as:
Route::get(/{param_1}/{value_1})
Route::get(/{param_1}/{value_1}/{param_2}/{value_2})
Route::get(/{param_1}/{value_1}/{param_2}/{value_2}/{param_3}/{value3})
Any thoughts?
Upvotes: 0
Views: 56
Reputation: 5082
I think get parameters are a perfect solution. But if you do want 'pretty URL's' you could do something like:
Route::get('/brands/{brand}', 'BrandController@search');
Route::get('/brands/{brand}/{model}', 'BrandController@search');
Route::get('/brands/{brand}/{model}/{location}', 'BrandController@search');
And then in your BrandController:
public function search($brand, $model = null, $location = null)
{
//
}
This way the $model
and $location
or optional. You can also make $brand
optional: $brand = null
. But the routes now require at least one parameter.
Upvotes: 1