F
Filament2mo ago
jigsaw

How to Populate(Fill) Spatie Media Library in Custom Form?

Hello everyone. I've built a custom page with form and the form has Spatie Media Library plugin. Form components are on a polymorhpic relation. I can successfully upload an image but on the edit page, I can't retrieve the image. How can I handle this?
public function mount(int|string $record): void
{
$this->record = $this->resolveRecord($record);

$this->form->fill($this->record->content?->toArray());
}

return $form
->schema([
SpatieMediaLibraryFileUpload::make('content.featured_image')
->collection('featured_image')
->imageEditor()
->imageResizeTargetHeight('290')
->imageResizeTargetWidth('375')
->imageEditorEmptyFillColor('#ffffff')
->acceptedFileTypes(['image/*']),
])
->statePath('data');
public function mount(int|string $record): void
{
$this->record = $this->resolveRecord($record);

$this->form->fill($this->record->content?->toArray());
}

return $form
->schema([
SpatieMediaLibraryFileUpload::make('content.featured_image')
->collection('featured_image')
->imageEditor()
->imageResizeTargetHeight('290')
->imageResizeTargetWidth('375')
->imageEditorEmptyFillColor('#ffffff')
->acceptedFileTypes(['image/*']),
])
->statePath('data');
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server