1
votes

I have this hierarchy for my products catalog:

Products -> Category -> Line -> Product

And the routes for this hierarchy:

Route::get('/products',                                         ['as' => 'site.products.index',    'uses' => 'Site\ProductsController@index']);
Route::get('/products/{categorySlug}',                          ['as' => 'site.products.category', 'uses' => 'Site\ProductsController@category']);
Route::get('/products/{categorySlug}/{lineSlug}',               ['as' => 'site.products.line',     'uses' => 'Site\ProductsController@line']);
Route::get('/products/{categorySlug}/{lineSlug}/{productSlug}', ['as' => 'site.products.product',  'uses' => 'Site\ProductsController@product']);

After that, there is some filters like, Chairs, Desks, Table, etc. When the user click in one filter, I will bring the products that has this filter.

I was think something like:

Route::get('/products/{categorySlug}/filter/{filterSlug}', ['as' => 'site.products.filter', 'uses' => 'Site\ProductsController@filter']);

But It will be in conflict with the others routes.

1

1 Answers

1
votes

You should put

Route::get('/products/{categorySlug}/filter/{filterSlug}', ['as' => 'site.products.filter', 'uses' => 'Site\ProductsController@filter']);

on the top just before

Route::get('/products/{categorySlug}/{lineSlug}/{productSlug}', ['as' => 'site.products.product',  'uses' => 'Site\ProductsController@product']);

which mean that laravel will try to match filter before the other one.