Skip to content

Instantly share code, notes, and snippets.

@jeffochoa
Created July 30, 2017 20:28
Show Gist options
  • Save jeffochoa/540190d881a7e0bc76e9bc234f2c6ff2 to your computer and use it in GitHub Desktop.
Save jeffochoa/540190d881a7e0bc76e9bc234f2c6ff2 to your computer and use it in GitHub Desktop.
Get collection of available routes in Laravel
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Routing\Route as Router;
class RouterServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Route::macro('getRoutesList', function () {
$routes = collect(Route::getRoutes())->map(function ($route) {
return [
'host' => $route->domain(),
'method' => implode('|', $route->methods()),
'uri' => $route->uri(),
'name' => $route->getName(),
'action' => $route->getActionName(),
];
});
return $routes;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment