Skip to content

Instantly share code, notes, and snippets.

@Sleavely
Created November 6, 2016 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sleavely/abd3cb3fa2b4dee869d820113be34750 to your computer and use it in GitHub Desktop.
Save Sleavely/abd3cb3fa2b4dee869d820113be34750 to your computer and use it in GitHub Desktop.
List all Laravel routes
<?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;
});
@jonaselan
Copy link

jonaselan commented Mar 21, 2018

Two things I have adapted to work with Laravel 5.6:

  1. Replace getPath for uri. line 10
  2. Replace text/plain for application/json. Actually, I did that to be coherent, after all the result will be a JSON. Line 16

@devqx
Copy link

devqx commented Jul 5, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment