Skip to content

Instantly share code, notes, and snippets.

@imliam
Created March 8, 2017 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imliam/80acf2cd24c7e5081475d3cd7d79bedb to your computer and use it in GitHub Desktop.
Save imliam/80acf2cd24c7e5081475d3cd7d79bedb to your computer and use it in GitHub Desktop.
Laravel 5 - Routing an unknown number of sub-levels
<?php
/*
|--------------------------------------------------------------------------
| Routing an unknown number of sub-levels
|--------------------------------------------------------------------------
|
| This is how you can route an unknown number of sub-levels and pass them
| to the same controller. For example, the following URLs will go through
| the same route:
|
| app.dev/
| app.dev/never
| app.dev/never/gonna
| app.dev/never/gonna/give
| app.dev/never/gonna/give/you
| app.dev/never/gonna/give/you/up
|
| Taken from: http://stackoverflow.com/a/31681869/2863542
|
*/
Route::get('/{sublevels?}', function($sublevels = null) {
if (!empty($sublevels)) {
$sublevels = explode('/', $sublevels);
}
dd($sublevels);
})->where('sublevels', '.*');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment