Created
March 8, 2017 16:01
-
-
Save imliam/80acf2cd24c7e5081475d3cd7d79bedb to your computer and use it in GitHub Desktop.
Laravel 5 - Routing an unknown number of sub-levels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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