F
Filamentβ€’2y ago
Crylar

Is it possible to group SpatieMediaLibraryFileUpload files under a directory?

I am not sure if I am doing something wrong or directory method is just ignored. I would like to group my uploaded files to be in products directory. What are my options?
Forms\Components\SpatieMediaLibraryFileUpload::make('images')
->image()
->multiple()
->maxFiles(3)
->enableReordering()
->collection('products')
->directory('products')
->acceptedFileTypes(['image/png', 'image/jpeg']),
Forms\Components\SpatieMediaLibraryFileUpload::make('images')
->image()
->multiple()
->maxFiles(3)
->enableReordering()
->collection('products')
->directory('products')
->acceptedFileTypes(['image/png', 'image/jpeg']),
7 Replies
Dan Harrin
Dan Harrinβ€’2y ago
i dont think spatie supports this natively whats the reason you want them in a directory? collections are used for that normally
Crylar
CrylarOPβ€’2y ago
Just wanted to organise everything a little bit better instead of storing everything right in the root folder of the drive. It is easy with a default FileUpload but I guess I will need to write a CustomPathGenerator for the Spatie plugin (based on their docs) to customise this. It would have been nice if a simple directory organised files into sub-directory. Oh well. πŸ™‚
wyChoong
wyChoongβ€’2y ago
You probably should be able to define another disk that point to a directory and use it for spatie
josef
josefβ€’2y ago
Yes, you can specify a custom disk and/or use a custom PathGenerator to generate the exact path you want, see spatie documentation and config for more information
Crylar
CrylarOPβ€’2y ago
Yeh, that's what I have done exactly. πŸ™‚
Romaldy
Romaldyβ€’2y ago
Hi everyone @Dan Harrin can you help me with this ? I'm trying to have a spatie media library in a popup from a page action like this.
Filament\Pages\Actions\Action::make($name)
->label(__('Attachments'))
->icon('heroicon-o-paper-clip')
->iconButton()
->modalWidth('xl')
->modalButton(__('Save'))
->slideOver()
->record($this->record)
->model($record::class)
->mountUsing(function (ComponentContainer $form, $record) {
$form->fill($record->toArray());
})
->action(function (array $arguments, ComponentContainer $form): void {
$model = $this->record::class;
$record = $this->record;
$form->model($record)->saveRelationships();
})
->form([
SpatieMediaLibraryFileUpload::make('attachments')
->disk('documents')
->multiple()
->responsiveImages()
->columnSpanFull(),
]);
Filament\Pages\Actions\Action::make($name)
->label(__('Attachments'))
->icon('heroicon-o-paper-clip')
->iconButton()
->modalWidth('xl')
->modalButton(__('Save'))
->slideOver()
->record($this->record)
->model($record::class)
->mountUsing(function (ComponentContainer $form, $record) {
$form->fill($record->toArray());
})
->action(function (array $arguments, ComponentContainer $form): void {
$model = $this->record::class;
$record = $this->record;
$form->model($record)->saveRelationships();
})
->form([
SpatieMediaLibraryFileUpload::make('attachments')
->disk('documents')
->multiple()
->responsiveImages()
->columnSpanFull(),
]);
where $this->record is the object with the data already Could you please tell me what i'm missing to make it work ?
Dan Harrin
Dan Harrinβ€’2y ago
pass ->record() OR ->model() if the record exists then pass that and the files will be saved automatically.
Filament\Pages\Actions\Action::make($name)
->label(__('Attachments'))
->icon('heroicon-o-paper-clip')
->iconButton()
->modalWidth('xl')
->modalButton(__('Save'))
->slideOver()
->record($this->record)
->mountUsing(function (ComponentContainer $form, $record) {
$form->fill($record->toArray());
})
->action(function (array $arguments, ComponentContainer $form): void {
//
})
->form([
SpatieMediaLibraryFileUpload::make('attachments')
->disk('documents')
->multiple()
->responsiveImages()
->columnSpanFull(),
]);
Filament\Pages\Actions\Action::make($name)
->label(__('Attachments'))
->icon('heroicon-o-paper-clip')
->iconButton()
->modalWidth('xl')
->modalButton(__('Save'))
->slideOver()
->record($this->record)
->mountUsing(function (ComponentContainer $form, $record) {
$form->fill($record->toArray());
})
->action(function (array $arguments, ComponentContainer $form): void {
//
})
->form([
SpatieMediaLibraryFileUpload::make('attachments')
->disk('documents')
->multiple()
->responsiveImages()
->columnSpanFull(),
]);
Want results from more Discord servers?
Add your server