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.
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.
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
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