Wallace, you can do as follows:
foreach (Route::getRoutes() as $route) {
var_dump($route->getUri());
}
The class Route
is a facade for class Illuminate\Routing\Router
in Laravel
.
So if you look at this class, it has a method called Router::getRoutes
. This method will return an instance of Illuminate\Routting\RouteCollection
, which is a collection of routes ( Illuminate\Routing\Route
not to confuse with Router
) that you added in Laravel
.
If you want to transform the object of class RouteCollection
to array
, just call the method getRoutes
again (however this time is RouteCollection
and not Router
).
So:
var_dump(Route::getRoutes()->getRoutes());
You can also capture the route name using the Illuminate\Routing\Route::getName()
method.
So:
foreach (Route::getRoutes() as $route) {
var_dump($route->getName());
}