Image validation not working

i have a rule for $attachOne

    public $rules = [
        'intro_image_mobile' => 'nullable|sometimes|image|dimensions:min_width=378,min_height=672,ratio=9/16',

But for some reason it is not working.

If the image is not uploaded by the customer then the validation should not take an effect therefore i used “nullable|sometimes”. => this is not working at all.

The resize is not working.

is there anything i am doing wrong here?

If you suspect the issue is nullable|sometimes, have you tried to add the rule in your model? something like :

public function beforeValidate()
    if ($this->intro_image_mobile) {
        // Add the validation rules conditionally
        $this->rules['intro_image_mobile'] = 'image|dimensions:min_width=378,min_height=672,ratio=9/16';

not sure if I written the rule correctly but this could be somewhere to start.


There was a related fix for this in the latest patch (v3.4.16), are you running the latest version?

@daft thanks alot.

yes i updated the core and now all working as expected.

@apinard thanks alot. Issue was in the core. But is good to know the before validate.

1 Like