F
Filament8mo ago
Joanne

Repeater shows only the first item on edit form

Hi, newbie here. I am using repeater to allow user to upload images when create article. The repeater repeatedly displays only the first image that was originally uploaded on edit form I have checked the data in the mutateFormDataBeforeFill function. The array of images ($data['images']) appears to contain all the uploaded images, but for some reason, only the first image is being displayed repeatedly.

Repeater::make('images')
->schema([ Forms\Components\SpatieMediaLibraryFileUpload::make('image')
->label('Image')
->collection(Article::MEDIA_COLLECTION_NAME)
->columnSpan('full')
->customProperties(['is_cover' => false])
// disk is s3_public
->disk(function () {
if (config('filesystems.default') === 's3') { return 's3_public';
}
})
->acceptedFileTypes(['image/*'])
->maxFiles(1)
->rules('image'),
])
->maxItems(20)
->collapsible()
->columnSpan('full')
->orderable('order_column')
->hidden(fn (Closure $get) => $get('type') !== 'multimedia'),

Repeater::make('images')
->schema([ Forms\Components\SpatieMediaLibraryFileUpload::make('image')
->label('Image')
->collection(Article::MEDIA_COLLECTION_NAME)
->columnSpan('full')
->customProperties(['is_cover' => false])
// disk is s3_public
->disk(function () {
if (config('filesystems.default') === 's3') { return 's3_public';
}
})
->acceptedFileTypes(['image/*'])
->maxFiles(1)
->rules('image'),
])
->maxItems(20)
->collapsible()
->columnSpan('full')
->orderable('order_column')
->hidden(fn (Closure $get) => $get('type') !== 'multimedia'),
the mutateFormDataBeforeFill function:

protected function mutateFormDataBeforeFill(array $data): array
{
$data['images'] = $this->record->getMedia(Article::MEDIA_COLLECTION_NAME)->toArray();
dd($data['images']);
return $data;
}
protected function mutateFormDataBeforeFill(array $data): array
{
$data['images'] = $this->record->getMedia(Article::MEDIA_COLLECTION_NAME)->toArray();
dd($data['images']);
return $data;
}

 Appreciate any insights on how I might resolve this issue.
2 Replies
Joanne
Joanne8mo ago
Hi, If anyone has thoughts or needs more details, please inform me. Thanks in advance!
Dennis Koch
Dennis Koch8mo ago
Not sure whether that will work with the spatie file upload. But at least the array structure is wrong. Why don’t you use multiple() on the file upload?