Skip to content

Commit 8ca1471

Browse files
Fix trashed implicitBinding with child with no softdelete (#41282) (#41814)
(cherry picked from commit b8be411) Co-authored-by: Jori Stein <[email protected]>
1 parent b4b39be commit 8ca1471

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Illuminate/Routing/ImplicitRouteBinding.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function resolveForRoute($container, $route)
4343
: 'resolveRouteBinding';
4444

4545
if ($parent instanceof UrlRoutable && ($route->enforcesScopedBindings() || array_key_exists($parameterName, $route->bindingFields()))) {
46-
$childRouteBindingMethod = $route->allowsTrashedBindings()
46+
$childRouteBindingMethod = $route->allowsTrashedBindings() && in_array(SoftDeletes::class, class_uses_recursive($instance))
4747
? 'resolveSoftDeletableChildRouteBinding'
4848
: 'resolveChildRouteBinding';
4949

tests/Integration/Routing/ImplicitRouteBindingTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,35 @@ public function testEnforceScopingImplicitRouteBindings()
142142
$response->assertNotFound();
143143
}
144144

145+
public function testEnforceScopingImplicitRouteBindingsWithTrashedAndChildWithNoSoftDeleteTrait()
146+
{
147+
$user = ImplicitBindingUser::create(['name' => 'Dries']);
148+
149+
$post = $user->posts()->create();
150+
151+
$user->delete();
152+
153+
config(['app.key' => str_repeat('a', 32)]);
154+
Route::scopeBindings()->group(function () {
155+
Route::get('/user/{user}/post/{post}', function (ImplicitBindingUser $user, ImplicitBindingPost $post) {
156+
return [$user, $post];
157+
})->middleware(['web'])->withTrashed();
158+
});
159+
160+
$response = $this->getJson("/user/{$user->id}/post/{$post->id}");
161+
$response->assertOk();
162+
$response->assertJson([
163+
[
164+
'id' => $user->id,
165+
'name' => $user->name,
166+
],
167+
[
168+
'id' => 1,
169+
'user_id' => 1,
170+
],
171+
]);
172+
}
173+
145174
public function testEnforceScopingImplicitRouteBindingsWithRouteCachingEnabled()
146175
{
147176
$user = ImplicitBindingUser::create(['name' => 'Dries']);

0 commit comments

Comments
 (0)