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.
ow 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');
}),
Was this page helpful?