List Routes Laravel
November 25, 2024 · AI Conversations
### Basic Command:
php artisan route:list
This will display a table with columns for `Method`, `URI`, `Name`, `Action`, and `Middleware`.
—
### Additional Options:
1. **Filtering by Method or Middleware:**
– Filter by a specific HTTP method:
php artisan route:list --method=GET
– Filter by middleware:
php artisan route:list --middleware=auth
2. **Searching for Routes:**
– Search by a specific term:
php artisan route:list --name=project
3. **Sorting:**
– Sort by a specific column, such as `uri`:
php artisan route:list --sort=uri
4. **Export to JSON or CSV:**
– Export to JSON for further processing:
php artisan route:list --json
– Export to CSV:
php artisan route:list --compact > routes.csv
5. **Compact Output:**
– For simpler output with fewer columns:
php artisan route:list --compact
—
### Common Debugging Scenarios:
– **Check for a specific route:**
Use the `–name` or `–path` option to find a specific route:
php artisan route:list --path=dashboard
– **Verify Middleware on Routes:**
Check if middleware like `auth` is applied:
php artisan route:list --middleware=auth
These commands provide flexibility and are particularly useful when working with a large number of routes in a Laravel application.