Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I list only the API routes for a specific version in Laravel 11
    laravel 11


How do I list only the API routes for a specific version in Laravel 11


To list only the API routes for a specific version in Laravel 11, you can use the `--path` option with the `route:list` command:

bash
php artisan route:list --path=api/v1

This will display only the routes that begin with the `/api/v1` prefix.

If you have defined your versioned API routes using separate files, as recommended in the Laravel documentation, you can use the following approach:

1. Define your versioned API routes in separate files, for example:
- `routes/api_v1.php`
- `routes/api_v2.php`

2. In your `routes/api.php` file, group the routes for each version using the `Route::prefix()` method:

php
Route::prefix('v1')->group(base_path('routes/api_v1.php'));
Route::prefix('v2')->group(base_path('routes/api_v2.php'));

3. To list the routes for a specific version, use the `--path` option with the `route:list` command:

bash
php artisan route:list --path=api/v1

This will display only the routes defined in the `routes/api_v1.php` file.

By separating your API routes into versioned files and using the `--path` option with `route:list`, you can easily view and manage the routes for each version of your API in Laravel 11[1][4].

Citations:
[1] https://laravel-news.com/api-versioning-in-laravel-11
[2] https://stackoverflow.com/questions/78188214/unable-to-locate-the-api-php-route-file-in-laravel-11
[3] https://www.youtube.com/watch?v=agUnf89SAOg
[4] https://www.youtube.com/watch?v=Tl_BbMDg-2o
[5] https://laravel.com/docs/11.x/routing