-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[9.x] Fix default parameter bug #42942
Conversation
Just tested it locally and the route is generated as expected. |
Feels a bit like we're entering into kinda rough territory here setting public properties before compiling, etc. I guess I will go ahead and merge this but if we run into anymore issues at all I think we should revert #42425 |
@driesvints @taylorotwell This causes issues with Octane and Url Defaults as described in this post I made on the laravel discord server:
|
This reverts commit 4d46bda.
We upgraded Laravel, but one of our tests started failing. Running tests locally, without Octane enabled. Same issue as Cole. In our test we're making a request, then follow the redirect returned from its response: $this
->actingAs($user)
->followingRedirects()
->post(route('checkout_cart', $store))
->assertViewIs('summary'); The route is defined as: Route::group(['domain' => config('app.domain'), 'prefix' => 'stores/{storeSlug}', 'middleware' => $middleware], function (): void {
Route::get('cart/checkout/summary', ShowCartCheckoutSummary::class)->name('checkout_cart');
}); We're also defining a default in a middleware: URL::defaults(['storeSlug' => $defaultStore->slug]) In in the initial request, the store (slug) is set (from the URL). In the second request, coming from the |
@sebastiaanluca we already reverted this pr and will be reverting all code related to the original pr as well soon. Tuesday's release will contain the fix. |
This took me the better part of the day to figure out but I finally found a solution that resolves #42707. After the introduction of #42425 several bugs got introduced as well. This is the last remaining one (we know of so far).
Let me try to explain the reasoning here. In the
compileParameterNames
of theRoute
object we return all parameter names of a route. These are mapped in an index array from 0 to up. Because this method has no knowledge of what a default parameter is it incorrectly matches a default param instead of the correct regular param. What we need to do is filter out the default params here before we try to map the regular passed params that we feed to theroute
method. TheRoute
object does not have any knowledge about these so we need to pass in to the route so it can filter the params out. Afterwards we can match our own params properly with the non-default ones.This fix is a bit of a crutch and I'm not 100% sure it's the correct one but without more examples I cannot make sure it's going to cover all use cases. At least all tests pass now.
Fixes #42707