11

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 

1 Answer 1

9

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')); 
Sign up to request clarification or add additional context in comments.

7 Comments

Hi sorry for the late Reply I get this error The "path" argument does not exist.
Check the answer. path is optional parameter so you need to add --path.
ok error vanished, but if I dd($routes) I get a 0, shouldn't it contain an error with my api routes
You can loop through the routes.
Something like this Returns all routes $routes = app()->routes->getRoutes(); but I do not know how to filter that
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.