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

[8.x] Backport - Fix trashed implicitBinding with child with no softdelete #41814

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/ImplicitRouteBinding.php
Expand Up @@ -43,7 +43,7 @@ public static function resolveForRoute($container, $route)
: 'resolveRouteBinding';

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

Expand Down
29 changes: 29 additions & 0 deletions tests/Integration/Routing/ImplicitRouteBindingTest.php
Expand Up @@ -142,6 +142,35 @@ public function testEnforceScopingImplicitRouteBindings()
$response->assertNotFound();
}

public function testEnforceScopingImplicitRouteBindingsWithTrashedAndChildWithNoSoftDeleteTrait()
{
$user = ImplicitBindingUser::create(['name' => 'Dries']);

$post = $user->posts()->create();

$user->delete();

config(['app.key' => str_repeat('a', 32)]);
Route::scopeBindings()->group(function () {
Route::get('/user/{user}/post/{post}', function (ImplicitBindingUser $user, ImplicitBindingPost $post) {
return [$user, $post];
})->middleware(['web'])->withTrashed();
});

$response = $this->getJson("/user/{$user->id}/post/{$post->id}");
$response->assertOk();
$response->assertJson([
[
'id' => $user->id,
'name' => $user->name,
],
[
'id' => 1,
'user_id' => 1,
],
]);
}

public function testEnforceScopingImplicitRouteBindingsWithRouteCachingEnabled()
{
$user = ImplicitBindingUser::create(['name' => 'Dries']);
Expand Down