Multiple FIleUpload Reorderable

Hey friends, I have little question on how things work. I have a FileUpload, multiple + reorderable, used a **saveRelationshipsUsing** to hook in to the saving part, but when I try to reorder them with **reorderUploadedFilesUsing**, it seems that its tries to go through this method (saveRelationshipsUsing) again after reorder and it removes the uploaded files from the filepond component visualy (after save), but after refresh they are still there. Also they don't appear to be sorted properly. How to prevent the files to disapear and how to force the images to come sorted, since the sortBy is not honored? How can I approach this? Here is my code:
FileUpload::make('images')
->multiple()
->label('Снимки')
->reorderable()
->minFiles(1)
->disk('uploads')
->directory('products')
->panelLayout('grid')
->saveRelationshipsUsing(function ($record, $state) {
$pos = intval($record->images()->count());
if(!is_null($state)){
foreach ($state as $path) {
$file = File::firstOrCreate([
'name' => basename($path),
'path' => $path,
'disk' => 'uploads',
]);
$record->images()->syncWithoutDetaching($file, [
'order' => $pos + 100,
'group' => 'images',
]);
}
}


})
->reorderUploadedFilesUsing(function ($record, $state) {
if ($state) {
foreach ($state as $pos => $path) {
$record->images()->where('path', $path)->update(['order' => $pos + 100]);
}
}
})
->deleteUploadedFileUsing(function ($record, $file) {
$file = $record->images()->where('path', $file)->first();
$record->images()->detach($file);
Storage::disk('uploads')->delete($file);
$file->delete();
})
->formatStateUsing(function ($record) {
return $record->images->sortBy('order')->pluck('path');
}),
FileUpload::make('images')
->multiple()
->label('Снимки')
->reorderable()
->minFiles(1)
->disk('uploads')
->directory('products')
->panelLayout('grid')
->saveRelationshipsUsing(function ($record, $state) {
$pos = intval($record->images()->count());
if(!is_null($state)){
foreach ($state as $path) {
$file = File::firstOrCreate([
'name' => basename($path),
'path' => $path,
'disk' => 'uploads',
]);
$record->images()->syncWithoutDetaching($file, [
'order' => $pos + 100,
'group' => 'images',
]);
}
}


})
->reorderUploadedFilesUsing(function ($record, $state) {
if ($state) {
foreach ($state as $pos => $path) {
$record->images()->where('path', $path)->update(['order' => $pos + 100]);
}
}
})
->deleteUploadedFileUsing(function ($record, $file) {
$file = $record->images()->where('path', $file)->first();
$record->images()->detach($file);
Storage::disk('uploads')->delete($file);
$file->delete();
})
->formatStateUsing(function ($record) {
return $record->images->sortBy('order')->pluck('path');
}),
2 Replies
slow
slow10mo ago
May I ask if you ever try to upload pdf file? I am newbie in filament. can you help me , how to upload pdf file because I am creating uploading file management and it needs to be a pdf format
Dimitar Papazov DEV
Dimitar Papazov DEVOP10mo ago
Thats off topic, but Just Use FileUpload::make() without any specifications and it will work for any type of file. Anyone, have an idea? up? bump
Want results from more Discord servers?
Add your server