The question seems realy simple, but I can't figure it out... How do you achieve slug-based dynamic pages with categories in Laravel 5.1?
Something like http://ift.tt/1Nocon1
I know that Route::get('/{slug}')
gives the "slug" as identifier, but the problem is that the page could be situated in http://ift.tt/1Suu6W4
, so if set the route to something like Route::get('/{category}/{subcategory}/{page}')
it will not work for the second example.
I was thinking about making 3 routes like
Route::get('/{category}/{subcategory}/{page}')
Route::get('/{category}/{page}')
Route::get('/{page}')
And then the controller to receive ($category = null, $subcategory = null, $page = null)
And in the controller something like
if (!$page)
$page = $subcategory;
if (!$page)
$page = $category;
Is there another, cleaner way to achieve this? Because here we have only 2 category routes, but there could be 3, 5 or more?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire