1
votes

I am working with backpackforlaravel ( "backpack/crud": "3.5.*"), it is great. I made an image CRUD section. I have a Requests file validation with the following code.

return [
            'name' => 'required|min:5|max:255',
            'code' => 'required|min:2|max:20',
            'image' => 'required|mimes:jpeg,png,jpg,gif|max:2048',
        ];

And in my controller I have this code

$this->crud->addField([ // image
            'label' => "Bandera",
            'name' => "image",
            'type' => 'image',
            'upload' => true,
            'crop' => false, // set to true to allow cropping, false to disable
            'aspect_ratio' => 1, // ommit or set to 0 to allow any aspect ratio
            'mime_types' => ['image'],
            'filesize'      => 5,
            // 'disk' => 's3_bucket', // in case you need to show images from a different disk
            // 'prefix' => 'uploads/images/profile_pictures/' // in case your db value is only the file name (no path), you can use this to prepend your path to the image src (in HTML), before it's shown to the user;
        ]);

Right now it is showing The image must be a file of type: jpeg, png, jpg, gif. The image may not be greater than 2048 characters.

It is validation the image weigh as a string and I need a normal weight and type validation

1
Could you please clarify - what is your question?MyStackRunnethOver
Hi, to clarify I need to validate the image field correctly, I need to validate the image weight, so, for example, I need to validate that the image's weight doesn't have to be more than 5 MB. But at now it is validation the image field like String characters. Additionally, I need to validate that the files uploaded should be images. ThanksDave More
I believe with 'weight' you mean 'filesize'.JorisJ1

1 Answers

1
votes

You are validating an image correctly when using that array of validators.

  • Validating mimes:jpeg,png,jpg,gif checks if it is an image.
  • Validating max:2048 puts a maximum on the filesize.