php - Laravel 4 dynamic route with multiple segments -
i create dynamic route allows multiple segments.
example.com/segment1 example.com/segment1/segment2/ example.com/segment1/segment2/segment3 using this:
route::get('{slug}', 'pagescontroller@index'); gives me first dynamic segment , of course this:
route::get('{slug1}/{slug2}', 'pagescontroller@index'); and on i'm sure there's better way this.
i believe 1 complication when using route::get('{slug1}/{slug2}', 'pagescontroller@index'); handling possible inputs segment1/segment2/ , foo/bar/. end lots of unnecessary logic.
this may not best solution believe groups work trying accomplish.
route::group(array('prefix' => 'segment1'), function() { route::get('/', 'controllerone@index'); route::group(array('prefix' => 'segment2'), function() { route::get('/', 'controllertwo@index); route::get('/segment3', 'controllerthree@index'); }); }); maybe little messy when dealing 3 examples end being beneficial , provide nicer hierarchy work with.
this has benefit using before , after filters. segment2 endpoints if want perform filter, instead of adding filter individual endpoints can add group!
route::group(array('before' => 'somefilter', 'prefix' => 'segment2'), function() { // ... ... });
Comments
Post a Comment