简体   繁体   中英

Laravel list routes in the view

How can I list routes specifically the api routes in my view?

For example These:

...api/user
...api/Information

The artisan command for example does list them like this:

php artisan route:list

In your controller you can get the list of routes using Artisan facade. I assume all your api routes have api string in its path.:

public function showRoutes($request) {
    $routes = Artisan::call('route:list', ['--path' => 'api']);
    return view('your_view', compact('routes'));  
}

Edit :

You can also use Route facades getRoutes method.

$routes = [];
foreach (\Route::getRoutes()->getIterator() as $route){
    if (strpos($route->uri, 'api') !== false){
        $routes[] = $route->uri;
    }
}
return view('your_view', compact('routes'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM