Category: Laravel, api

When creating a catch-all route in Laravel, you might encounter conflicts with others routes in your application. In this post I would like to describe how you can resolve some of these conflicts. One use case for a catch-all route, is when you want to serve a single page application, for example with Vue.js, and let the JavaScript Framework handle all the routes.

This makes it easier to navigate to the controller, and will help during refactoring in most IDEs.

However, a cleaner solution would be to ignore the /admin, and /api routes in the catch-all route by adding a regular expression constraint, and make the any parameter optional: This will give you the freedom to order your route definitions logically instead of functionally.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners