diff --git a/src/MediaCollections/Models/Collections/MediaCollection.php b/src/MediaCollections/Models/Collections/MediaCollection.php index 5081e9a9f..a549d03f5 100644 --- a/src/MediaCollections/Models/Collections/MediaCollection.php +++ b/src/MediaCollections/Models/Collections/MediaCollection.php @@ -52,19 +52,21 @@ public function toHtml() public function jsonSerialize() { - return ($this->formFieldName ?? $this->collectionName) - ? old($this->formFieldName ?? $this->collectionName) - : $this->map(function (Media $media) { - return [ - 'name' => $media->name, - 'file_name' => $media->file_name, - 'uuid' => $media->uuid, - 'preview_url' => $media->hasGeneratedConversion('preview') ? $media->getUrl('preview') : '', - 'order' => $media->order_column, - 'custom_properties' => $media->custom_properties, - 'extension' => $media->extension, - 'size' => $media->size, - ]; - })->keyBy('uuid'); + if (!($this->formFieldName ?? $this->collectionName)) { + return []; + } + + return old($this->formFieldName ?? $this->collectionName) ?? $this->map(function (Media $media) { + return [ + 'name' => $media->name, + 'file_name' => $media->file_name, + 'uuid' => $media->uuid, + 'preview_url' => $media->hasGeneratedConversion('preview') ? $media->getUrl('preview') : '', + 'order' => $media->order_column, + 'custom_properties' => $media->custom_properties, + 'extension' => $media->extension, + 'size' => $media->size, + ]; + })->keyBy('uuid'); } }