Laravel-Backpack / community-forum

A workspace to discuss improvement and feature ideas, before they're actually implemented.
28 stars 0 forks source link

[BUG] ValidUploadMultiple - False validation while updating #983

Open karandatwani92 opened 1 month ago

karandatwani92 commented 1 month ago

Discussed in https://github.com/Laravel-Backpack/community-forum/discussions/982

Originally posted by **marctaule** May 11, 2024 Hi! I have a problem with the 'upload_multiple' field when updating content. I have the 'images' field among others, and it's an optional field. If I don't have any image and I add one, it works correctly. But when I try to edit other fields, it always tells me: 'The images field must be a file of type: jpeg, png, jpg, gif, svg.' I attach the code I have: This is my rule: `public function rules() { return [ 'name' => 'required|string', 'images' => ValidUploadMultiple::field()->file('mimes:jpeg,png,jpg,gif,svg|max:2048'), ]; }` This is my code in CrudController: `CRUD::field([ 'name' => 'images', 'label' => 'Images', 'type' => 'upload_multiple', 'withFiles' => [ 'disk' => 'public', // the disk where file will be stored 'path' => 'images', // the path inside the disk where file will be stored ], 'wrapper' => [ 'class' => 'form-group col-md-6 mb-3' ] ]);` I try different type of field in my database: text, varchar and json and no one work :( Can anyone help me? Thanks!

[BUG-TLDR]

Throws false validation error when upload_multiple already has an item and we update without changes.

CRUD::field(
[
   'name'      => 'images',
   'label'     => 'Images',
   'type'      => 'upload_multiple',
   'withFiles' => [
       'disk' => 'public',
       'path' => 'images'
    ],
   'wrapper' => ['class' => 'form-group col-md-6 mb-3']
]);
public function rules()
{
   return [
       'images' => ValidUploadMultiple::field()->file('mimes:jpeg,png,jpg,gif,svg|max:2048')
    ];
}
marctaule commented 1 month ago

Hi! When do you think you will be able to fix this bug? I need it for one of my projects :( Thanks!

karandatwani92 commented 1 month ago

Hey @marctaule Sorry for the inconvenience.

We are doing a big rework on uploaders, adding tests, bug fixes, and drag-drop Ajax upload support for the editor(similar to the GitHub comment box), etc. It is our priority and is currently in the test phase. It's big, thus taking time. It's in https://github.com/Laravel-Backpack/CRUD/pull/5478

Meanwhile, you can do this: