Laravel list routes in the view
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
# Listing Only API Routes in Your Laravel View: A Developer's Guide
As a senior developer working with Laravel, you frequently deal with applications that serve both traditional web pages and dedicated APIs. A common requirement is the need to clearly delineate which routes are intended for public consumption (API endpoints) versus those serving the main application interface. When you use `php artisan route:list`, you get a comprehensive list of everything, but often, you only want to display the API routes within a specific section of your application's view.
This guide will walk you through the most effective and developer-friendly ways to selectively list only your API routes in a Blade view, ensuring clarity and maintainability.
## Why Standard Route Listing Isn't Enough
When you run `php artisan route:list`, Laravel dumps all defined routes, including web routes (`web`) and API routes (`api`), into a single output. While useful for debugging, this isn't ideal for presentation within a specific view. We need a programmatic way to filter these routes based on their URI prefix (e.g., routes starting with `/api`).
The goal is to iterate through the routes defined in your application and select only those matching the API pattern. This approach leverages Laravelâs powerful routing system, which is a cornerstone of what makes frameworks like Laravel so extensible and powerful, as showcased on [laravelcompany.com](https://laravelcompany.com).
## Method 1: Programmatic Filtering using the Route Facade
The most robust way to achieve this is by directly querying the `Route` facade within your controller or view logic. We can iterate over all registered routes and apply a condition to filter them specifically for those prefixed with `/api`.
Here is an example demonstrating how you might fetch and display only the API routes in a Blade file:
```php
uri, '/api') === 0) {
$apiRoutes[] = [
'method' => $route->methods(),
'uri' => $route->uri(),
'name' => $route->getName(),
];
}
}
// Pass the filtered data to the view
return view('api_routes', compact('apiRoutes'));
}
}
```
In your `resources/views/api_routes.blade.php`, you can then loop through this collection:
```html
API Endpoints
-
@foreach ($apiRoutes as $route)
- Method: {{ $route['method'] }} | URI: {{ $route['uri'] }} | Name: {{ $route['name'] }} @endforeach