Does Spatie Media Library works with Relation Manager?
Every time i'm trying to combine both, i'm receiving:
Field 'collection_name' doesn't have a default value
Is there any possibility to add media through Spatie Media Library by CreateAction in Relation Manager?
2 Replies
Ok, i've the right solutions to achive this:
Tables\Actions\Action::make('mediaUpload')
->label('Upload file')
->form([
FileUpload::make('file')
->required()
->storeFiles(false)
->label('Upload file'),
])
->action(function (array $data, self $livewire) {
$file = $data['file'];
if ($file instanceof UploadedFile) {
$livewire->ownerRecord
->addMedia($file)
->preservingOriginal()
->toMediaCollection('default');
}
}),
Any particular reason you are not using the official plug-in for spatie media?
https://filamentphp.com/plugins/filament-spatie-media-library
Filament
Spatie Media Library by Filament - Filament
Filament support for Spatie's Laravel Media Library package.