F
Filamentβ€’8mo ago
Alexandre

Help for Spatie Media File Upload in Relation Manager

Hello all πŸ‘‹, I use Filament's Spatie Media Library plugin. I have my media table and a Model named "Company" where I would like to link files but not in the create page. So, I've created a RelationManager for my medias to be able to access the files in the company view, but I'm not sure how to manage adding files... If I place the prebuild createAction in the header array, the button doesn't appear. So I try to build a custom one. For now, I've this :
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([ // ])
->filters([ // ])
->headerActions([
Tables\Actions\Action::make('Add a media to this company')
->label(__('admin/medias.actions.add_media'))
->form([
Forms\Components\TextInput::make('name'),
Forms\Components\SpatieMediaLibraryFileUpload::make('attachment')
->collection('companies')
->acceptedFileTypes(['application/pdf', 'image/*'])
->required()
->reorderable()
->multiple(),
])
->action(function (array $data) {
dd($data); //$data returns an empty array...
$record = $this->ownerRecord;
$record->addMedia($data['attachment'])->toMediaCollection('companies');
}),
])
->actions([ // ])
->bulkActions([ // ]),
]);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([ // ])
->filters([ // ])
->headerActions([
Tables\Actions\Action::make('Add a media to this company')
->label(__('admin/medias.actions.add_media'))
->form([
Forms\Components\TextInput::make('name'),
Forms\Components\SpatieMediaLibraryFileUpload::make('attachment')
->collection('companies')
->acceptedFileTypes(['application/pdf', 'image/*'])
->required()
->reorderable()
->multiple(),
])
->action(function (array $data) {
dd($data); //$data returns an empty array...
$record = $this->ownerRecord;
$record->addMedia($data['attachment'])->toMediaCollection('companies');
}),
])
->actions([ // ])
->bulkActions([ // ]),
]);
}
Do you know how I can do this or maybe there is a simpler way? Thanks in advance πŸ™‚
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server