diff --git a/src/Pages/NestedEditRecord.php b/src/Pages/NestedEditRecord.php index c3ef0dd..e12e910 100644 --- a/src/Pages/NestedEditRecord.php +++ b/src/Pages/NestedEditRecord.php @@ -26,18 +26,17 @@ protected function configureDeleteAction(DeleteAction $action): void $ancestorResource = $ancestor->getResource(); + $urlParameters = $ancestor->getNormalizedRouteParameters($this->getRecord()); + + $redirectUrl = match (true) { + $resource::hasPage('index') => $resource::getUrl('index', $urlParameters), + $ancestorResource::hasPage('view') => $ancestorResource::getUrl('view', $urlParameters), + default => $ancestorResource::getUrl('edit', $urlParameters), + }; + $action ->authorize($resource::canDelete($this->getRecord())) - ->successRedirectUrl( - $resource::hasPage('index') - ? $resource::getUrl('index', [ - ...$ancestor->getNormalizedRouteParameters($this->getRecord()), - ]) - : $ancestorResource::getUrl('edit', [ - ...$ancestor->getNormalizedRouteParameters($this->getRecord()), - ]) - ) - ; + ->successRedirectUrl($redirectUrl); } protected function configureForceDeleteAction(ForceDeleteAction $action): void @@ -54,18 +53,17 @@ protected function configureForceDeleteAction(ForceDeleteAction $action): void $ancestorResource = $ancestor->getResource(); + $urlParameters = $ancestor->getNormalizedRouteParameters($this->getRecord()); + + $redirectUrl = match (true) { + $resource::hasPage('index') => $resource::getUrl('index', $urlParameters), + $ancestorResource::hasPage('view') => $ancestorResource::getUrl('view', $urlParameters), + default => $ancestorResource::getUrl('edit', $urlParameters), + }; + $action ->authorize($resource::canForceDelete($this->getRecord())) - ->successRedirectUrl( - $resource::hasPage('index') - ? $resource::getUrl('index', [ - ...$ancestor->getNormalizedRouteParameters($this->getRecord()), - ]) - : $ancestorResource::getUrl('edit', [ - ...$ancestor->getNormalizedRouteParameters($this->getRecord()), - ]) - ) - ; + ->successRedirectUrl($redirectUrl); } protected function configureViewAction(ViewAction $action): void