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.
Background
Currently, two routes with the same path and method are breaking the route cache. A routes file containing the following routes
will break the
artisan route:cache
command with the following exception:This is a problem if you want to overwrite routes from a vendor package (for example Spark). Also see: #7452
The underlaying problem
Adding the second route to the
RouteCollection
overwrites the first route of$routes
and$allRoutes
. However, the old route is still in the action look-up table$actionList
(and in$nameList
, if the route has a name).The
RouteCacheCommand
iterates over$routes
ofRouteCollection
and serializes all routes. It cannot serialize the first, old route because it is not in$routes
anymore. This causes the exception.Solution
The clean solution is to to keep the
$actionList
and$nameList
always up to date and avoid keeping outdated routes. There is already a methodrefreshNameLookups()
to refresh the name look-up table. I added the same method for the action look-up table (refreshActionLookups()
). I changed theRouteCacheCommand
to use these methods.