Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of registered route paths in Laravel?

I was hoping to find a way to create an array with the registered routes paths within Laravel 4.

Essentially, I am looking to get a list something like this returned:

/ /login /join /password 

I did come across a method Route::getRoutes() which returns an object with the routes information as well as the resources but the path information is protected and I don't have direct access to the information.

Is there any other way to achieve this? Perhaps a different method?

like image 400
Kevin Jung Avatar asked Aug 23 '13 04:08

Kevin Jung


People also ask

What is the command to list all routes?

The route:list command can be used to show a list of all the registered routes for the application. This command will display the domain, method, URI, name, action and middleware for the routes it includes in the generated table.

What is Route Group in Laravel?

Route groups allow you to share route attributes, such as middleware, across a large number of routes without needing to define those attributes on each individual route.


1 Answers

Route::getRoutes() returns a RouteCollection. On each element, you can do a simple $route->getPath() to get path of the current route.

Each protected parameter can be get with a standard getter.

Looping works like this:

$routeCollection = Illuminate\Support\Facades\Route::getRoutes();  foreach ($routeCollection as $value) {     echo $value->getPath(); } 
like image 181
netvision73 Avatar answered Oct 24 '22 13:10

netvision73