Has anyone implemented repeaters, that include Spatie Media Library inputs?
I found some posts from 2023 and older with no real solutions - is there a better approach nowadays?
I've managed to add a hidden field in customProperties, but I can't figure out how to properly configure filterMediaUsing to show the correct image (without it, it shows the first repeater block one as expected)
Forms\Components\Repeater::make('content')
->label('Sections')
->schema([
Forms\Components\TextInput::make('title')->label('Section Title'),
Forms\Components\RichEditor::make('body')->label('Content'),
Forms\Components\Hidden::make('image_id')
->default(fn() => Str::random(12)),
SpatieMediaLibraryFileUpload::make('image')
->collection('service')
->disk('public')
->responsiveImages()
->image()
->maxSize(2048)
->customProperties(fn(Forms\Get $get) => ['gallery_id' => $get('gallery_id')])
->filterMediaUsing(function (Collection $media, Forms\Get $get) {
return $media->filter(function (Media $item) use ($get) {
return $item->custom_properties['gallery_id'] === $get('gallery_id');
});
})
])