diff --git a/packages/actions/src/Action.php b/packages/actions/src/Action.php index 09141961ad..b193036741 100644 --- a/packages/actions/src/Action.php +++ b/packages/actions/src/Action.php @@ -474,8 +474,8 @@ class Action extends ViewComponent implements Arrayable || (! $record instanceof Model) || blank($table->getModel()) || ($record::class === $table->getModel()) - )) { - $context['recordKey'] = $this->resolveRecordKey($record); + ) && filled($recordKey = $this->resolveRecordKey($record))) { + $context['recordKey'] = $recordKey; } if ($table && $this->isBulk()) { diff --git a/packages/actions/src/Concerns/InteractsWithRecord.php b/packages/actions/src/Concerns/InteractsWithRecord.php index a7841a0991..f4f89636dc 100644 --- a/packages/actions/src/Concerns/InteractsWithRecord.php +++ b/packages/actions/src/Concerns/InteractsWithRecord.php @@ -155,13 +155,19 @@ trait InteractsWithRecord /** * @param Model | array $record */ - public function resolveRecordKey(Model | array $record): string + public function resolveRecordKey(Model | array $record): ?string { if (is_array($record)) { - return $record[ArrayRecord::getKeyName()] ?? throw new LogicException('Record arrays must have a unique [' . ArrayRecord::getKeyName() . '] entry for identification.'); + return strval($record[ArrayRecord::getKeyName()] ?? throw new LogicException('Record arrays must have a unique [' . ArrayRecord::getKeyName() . '] entry for identification.')); } - return $record->getKey(); + $key = $record->getKey(); + + if (blank($key)) { + return null; + } + + return strval($key); } public function getCustomRecordTitle(?Model $record = null): ?string