Laravel-Backpack / community-forum

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

[Bug] The File/Image validation rule does not work on the Image field #893

Closed tringuyenduc2903 closed 3 months ago

tringuyenduc2903 commented 3 months ago

Bug report

What I did

Create a field with type image

What I expected to happen

Can Validate with image or file

public function rules(): array
{
  ...
  'image' => ['image'],
  \\ or 'image' => ['file'],
  ...
}

What happened

Only works with type upload image

What I've already tried to fix it

public function rules(): array
{
  ...
'image' => ['regex:/^data:image/'],
  ...
}

Is it a bug in the latest version of Backpack?

After I run backpack composer update backpack/crud the error it still persists

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is: image

pxpm commented 3 months ago

Hello @tringuyenduc2903

Image field sends a base64 string. You need to use a special package to validate image fields.

We are re-working the whole uploaders system including validation, and will consider creating a ValidationRule for image too.

https://github.com/crazybooot/base64-validation

I've been using this package with success to validate base64 strings. At the moment it does not support Laravel 11, but there is a branch there already by shift, so you can use that temporary branch until they merge the L11 support.

Hope it helps 🙏

Cheers