© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
5 replies
Dimitar

Multiple FIleUpload Reorderable

Hey friends, I have little question on how things work.

I have a FileUpload, multiple + reorderable, used a
**saveRelationshipsUsing**
**saveRelationshipsUsing**
to hook in to the saving part, but when I try to reorder them with
**reorderUploadedFilesUsing**
**reorderUploadedFilesUsing**
, it seems that its tries to go through this method (
saveRelationshipsUsing
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
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');
}),
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Multiple FileUpload
FilamentFFilament / ❓┊help
16mo ago
Multiple file upload grid Reorderable not working
FilamentFFilament / ❓┊help
2y ago
Layout in fileupload multiple
FilamentFFilament / ❓┊help
3y ago
FileUpload issue with multiple machines
FilamentFFilament / ❓┊help
2y ago