2

I need to get a list of the paths of all routes programmatically.

I tried Route::getRoutes() - not working in L5. RouteCollection::getRoutes() - is not a static method.

I bet I can get the RouteCollection from $request, but I don't know how.

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
koem
  • 554
  • 4
  • 24

2 Answers2

3

Route::getRoutes(); should work, you might have forget to import the route class (facade). Then you iterate the list:

$routeList = Route::getRoutes();

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

Remeber to import

use Illuminate\Support\Facades\Route;

This is tested on Laravel 5.2

Documenation

Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
3

First

use Illuminate\Support\Facades\Route;

For all routes use this code

$routeList=Route::getRoutes();
    foreach ($routeList as $value) {
        echo $value->getPath();
    }

For current route name use this code

$currentPath= Route::getFacadeRoot()->current()->uri();

For details information, read this two posts, All Routes

and Current Route

Community
  • 1
  • 1
Md Rashedul Hoque Bhuiyan
  • 10,151
  • 5
  • 30
  • 42