yekowele's avatar

Get all routes with Route facade.

Hello everynone,

I'm accessing route list with Route::getRoutes()->get() but when i cache routes with php artisan route:cache it's returns empty array, it returns nothing.

How i list all routes with / while i'm using route:cache?

Thank you

Here is full code :

 private function getRoutes(){
        $routes = Route::getRoutes()->get();
        $groupRoutes = [];

        foreach ($routes as $route){
            $action = $route->getAction();
            if (isset($action['middleware']) && in_array('language', $action['middleware'])){
                $groupRoutes[] = $route->getName();
            }
        }
        return $groupRoutes;
    }
0 likes
1 reply
gych's avatar

You can use $routes = app()->router->getRoutes(); to get the cached routes

Please or to participate in this conversation.