Is there any way to capture unlimited levels of URLs of sub-pages. My application allows any user to create any level of sub-pages. In my pages table I have parentID.
/{page}/{subpage} // this captures 2 level of pages
/{page} // this captures 1 level of page
I want to capture all URLs ranging from
site.com/food/healthy/fruit/red/apple to site.com/fruit/organge or site.com/grapes or site.com/a/b/c/d/e/f/g/h/i/j and so on.
what would be the most efficient way?
Sure it's possible. You'd need to explode the captured pages on the slash / and go from there though.
Route::any('{any}', function($pages)
{
$pages = explode('/', $pages);
// Do whatever...
})->where('any', '.*');
A few things to be aware of:
Route::any in the above to capture any request (POST, GET, etc), you might want to limit this to a subset of those or only GET, that's up to you.URL::route helper but you can still make use of the URL::to helper. This shouldn't be a problem as it's more than likely you're storing these dynamic pages in a database and as such the URI should be stored within the database as well.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With