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.
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.