Created
November 6, 2016 17:15
-
-
Save Sleavely/abd3cb3fa2b4dee869d820113be34750 to your computer and use it in GitHub Desktop.
List all Laravel routes
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 | |
// List all routes as a prettyprinted JSON array. | |
// Compatible with Laravel 4 and 5. | |
Route::get('routes', function(){ | |
$routes = Route::getRoutes(); | |
$results = array(); | |
foreach ($routes as $route) | |
{ | |
$path = $route->getPath(); | |
$readable = preg_replace('/\/\{(one|two|three|four|five)\?\}/', '', $path); | |
$results[] = $readable; | |
} | |
sort($results); | |
$response = Response::make(json_encode($results, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)); | |
$response->header('Content-Type', 'text/plain'); | |
return $response; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two things I have adapted to work with Laravel 5.6:
getPath
foruri
. line 10text/plain
forapplication/json
. Actually, I did that to be coherent, after all the result will be a JSON. Line 16