Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort routes by model binding in RouteCollection #53031

Closed
wants to merge 1 commit into from

Conversation

AbedollahAbuGozah
Copy link

Overview: This pull request addresses the route handling in Laravel's RouteCollection. It ensures that routes with model binding are properly prioritized during sorting.

Changes Made:

Implemented logic in RouteCollection.php to sort routes by their model binding. Routes without model bindings will now appear first, allowing for expected behavior when defining routes.
Specifically, routes like x/{param} should be placed after any routes with static segments, such as x/something, to function correctly.

Added comprehensive tests in RouteCollectionTests.php to validate the new sorting mechanism and ensure that the changes do not break existing functionality.
Benefits: This change improves the predictability of route resolution, especially in cases where static routes may conflict with dynamic model-bound routes.

- Updated the sort logic in the RouteCollection class to prioritize routes without model bindings, ensuring they appear first in the collection.
- Added tests in RouteCollectionTests to validate the new sorting behavior.
@taylorotwell
Copy link
Member

You should just define them this way in your routes file. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants