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

0 votes

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

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?

Mar 31 in Laravel by kartik
• 10,990 points
111 views

1 answer to this question.

0 votes

Hello,

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 = Route::getRoutes();

foreach ($routeCollection as $value) {
    echo $value->getPath();
}

Thank you!!

answered Mar 31 by Niroj
• 22,110 points

Related Questions In Laravel

0 votes
1 answer

How to identify wheather the request is HTTP GET or HTTP POST in Laravel?

Hey, In order to identify the type of ...READ MORE

answered Mar 19 in Laravel by Niroj
• 22,110 points
39 views
0 votes
1 answer

How to mock a static facade methods in Laravel?

Hey, Facades provide a "static" interface to classes ...READ MORE

answered Mar 19 in Laravel by Niroj
• 22,110 points
108 views
0 votes
1 answer

How to get user's IP address in Laravel?

Hey, We can get the user's IP address ...READ MORE

answered Mar 20 in Laravel by Niroj
• 22,110 points
332 views
0 votes
1 answer

How to make a constant and use globally in laravel?

Hii, You can create a constants.php page in config folder ...READ MORE

answered Mar 24 in Laravel by Niroj
• 22,110 points
34 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,110 points
417 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,110 points
62 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,110 points
64 views
0 votes
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,110 points
139 views
0 votes
1 answer

.How to turn off CSRF protection for a particular route in Laravel?

Hey, We can add that particular URL or ...READ MORE

answered Mar 24 in Laravel by Niroj
• 22,110 points
84 views
0 votes
1 answer

How to add a new column to existing table of laravel in a migration?

Hii @kartik, To create a migration, you may ...READ MORE

answered Mar 30 in Laravel by Niroj
• 22,110 points
479 views