Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] image [pro] field validation #5702

Closed
manfield opened this issue Oct 22, 2024 · 4 comments
Closed

[Bug] image [pro] field validation #5702

manfield opened this issue Oct 22, 2024 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@manfield
Copy link

manfield commented Oct 22, 2024

Bug report

What I did

According to documentation:

[Step 7.](https://backpackforlaravel.com/docs/6.x/upgrade-guide#step-7) (OPTIONAL) If you were manually validating the upload, upload_multiple or image field to do complex stuff, v6 provides an easier way to do it; check [the upload field docs](https://backpackforlaravel.com/docs/6.x/crud-fields#upload), [upload_multiple field docs](https://backpackforlaravel.com/docs/6.x/crud-fields#upload_ultiple_) for the new validation classes we've introduced - ValidUpload and ValidUploadMultiple;

image validation should be possible as it is for the upload field.

I created a CrudController containing this field:

            [
                'name'  => 'cover',
                'type'  => 'image',
                'label' => trans('custom.cover'),
                'withMedia' => ['displayConversions' => 'thumbnail'],
                'tab' => trans('custom.main'),
                'hint'       => trans('custom.image_upload_rule'),
                'validationRules' => 'mimes:jpg,jpeg,png|max:3000',
            ],

same exact behaviour if I move validation to the ModelCrudRequest file like this:

use Backpack\CRUD\app\Library\Validation\Rules\ValidUpload;

    public function rules()
    {
        return [
            'cover' => ValidUpload::field()
                ->file('mimes:jpg,jpeg,png|max:3000'),
      ];
    }

What I expected to happen

I expect image is processed as any other upload.
Instead validation always fails, even if the constraints are satisfied.

Is it a bug in the latest version of Backpack?

yes

Backpack, Laravel, PHP, DB version

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

### PHP VERSION:
8.3.9

### PHP EXTENSIONS:
Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, random, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, ast, bcmath, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, iconv, igbinary, intl, exif, msgpack, mysqli, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, readline, redis, shmop, SimpleXML, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, zip, memcached, Zend OPcache, xdebug

### LARAVEL VERSION:
11.23.5.0

### BACKPACK PACKAGE VERSIONS:
backpack/basset: 1.3.6
backpack/crud: 6.7.41
backpack/devtools: 3.1.6
backpack/generators: v4.0.6
backpack/language-switcher: 2.0.0
backpack/medialibrary-uploaders: 1.2.1
backpack/permissionmanager: 7.2.1
backpack/pro: 2.2.21
backpack/settings: 3.1.1
backpack/theme-tabler: 1.2.13
backpack/translation-manager: 1.0.4
@manfield
Copy link
Author

may cause #5409

@karandatwani92
Copy link
Contributor

Hey @manfield

Yes, your right.. sorry for the inconvinience. Thanks for reporting the bug.
Screenshot 2024-10-23 at 9 37 51 PM

@karandatwani92
Copy link
Contributor

Hey @pxpm

Add following to app/Http/Requests/ProductRequest.php to reproduce.

'main_image' => ValidUpload::field('required')->file('file|mimes:jpeg,jpg,png,jpg,gif,svg|max:2048'),

@pxpm
Copy link
Contributor

pxpm commented Oct 24, 2024

Hey @karandatwani92 I think we have already talked about this before.

ValidUpload is for upload field, ValidUploadMultiple for upload_multiple and so on.

The image fields sends a base64 encoded string. For that you require something that can validate base64.

Here is my answer on a previous question regarding the same subject: Laravel-Backpack/community-forum#722 (comment)

We don't want to introduce a dependency just for validating one field type, so we are considering creating a separate package backpack/image-field-validation that can require that base64 validation package and add there the ValidImage similar to how we have the other validation rules for uploaders.

Cheers

@pxpm pxpm assigned karandatwani92 and unassigned pxpm Oct 24, 2024
@karandatwani92 karandatwani92 added the question Further information is requested label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
Status: Done
Development

No branches or pull requests

3 participants