[13.x] Register subdomain routes before routes that are not linked to a domain #55921
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?
Currently, it is not possible to register a subdomain route that catches all requests to that subdomain (a fallback route). This is only possible if this route is registered before any other routes are registered. That can not be (easily) achieved when packages installed in the project are also registering routes, and if this catch-all subdomain route is registered inside a package itself.
You could say: link all root domain routes explicitly to a root domain, but that is a very heavy and big change you would have to make throughout your project (and its installed packages), and won't work if there are multiple root domains.
How?
This PR fixes that. It moves all subdomain routes to the top of the route collection. It still respects the registration order of those subdomain routes. By moving the subdomain routes to the top of the route collection, they will be checked first when a request comes in.
Implications?
I targeted the master branch, just be sure, although I can't seem to think of a way this breaks existing applications. If there are domain routes registered across multiple domains in a project, then the order of those route registrations is still the preserved.
This would also mean that the following warning on https://laravel.com/docs/12.x/routing#route-group-subdomain-routing can be removed:
