How to get routes lists in Laravel 7.x and 6.x ?

February 27, 2018 | Category : Laravel 5.6 Laravel 5.5 Laravel 5 Laravel PHP

Hi Guys, in this article, I will explain how to get all routes lists using getRoutes() in Laravel 5 app. we can simply get registered routes in laravel 5.6 application. we will use Route facade with getRoutes() method for getting all list of routes.

If you require to generate and get all list of routes then you can get it by using this way : "Route::getRoutes()" , Then you can simply get following thing.

Routes List

$route->getName()

$route->uri

$route->getPrefix()

$route->getActionMethod()

Now at bellow we will see full example with creation of dummy routes then we wil get list of routes. so let's add following routes in bellow web.php file.

routes/web.php

Route::get('get-all-route', function () {

$getRouteCollection = Route::getRoutes(); //get and returns all returns route collection


foreach ($getRouteCollection as $route) {

echo $route->getName();

}

});

I hope you like........