Answer the question
In order to leave comments, you need to log in
How to set dynamic number of parameters in URI (Routes) laravel?
Let's say the site has a list of products, I need to configure their filtering.
For example, the output of goods by city, by category or by manufacturer. I can process each one individually, but what if I need to make a selection by city and category? Or by city and manufacturer?
I'm trying to do this (code in Routes.php):
Route::group(['prefix' => '/{city_name?}/{category_name?}/{firm_name?}/'], function() {
Route::get('/', '[email protected]');
});
public function index($city_name=0,$category_name=0,$firm_name=0){}
Answer the question
In order to leave comments, you need to log in
Your routes could look something like this
and your controller is something like this
public function index(Request $request)
{
$cityName = '';
$categoryName= '';
$firmName= '';
if(isset($request->city_name) || isset($request->category_name) || isset($request->firm_name)){
//POST случай делаешь свои выборки, получаешь $списокТоваров
}
if(!isset($списокТоваров)){
//GET случай, когда первый раз зашёл на страницу.
}
return view('/', compact('списокТоваров', 'cityName ', 'categoryName', 'firmName'));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question