V
V
volodec2018-03-30 13:30:58
Laravel
volodec, 2018-03-30 13:30:58

How to make image validation work in Laravel FormRequest?

There is a FormRequest created with the name ModelRequest, it has rules for validating images when creating a model

protected $rules = [
    'image_primary' => 'required|image',
    'image_secondary' => 'nullable|image'
];
public function rules() {
    return $this->rules;
  }

This FormRequest inherits ModelUpdateRequest
class ModelUpdateRequest extends ModelRequest{
public function rules() {
    $this->rules['image_primary'] = 'nullable|image';

    return $this->rules;
  }
}

As you can see, the inheriting FormRequest only changes the value of image_primary.
So, the parent request works as it should, but the successor always gives an image file validation error. Moreover, both the first (image_primary) and the second (image_secondary), the validation rules of which have not changed. There have been attempts to replace the image rule with mimetypes:image/* , but this has not been successful.
I am using Laravel 5.6

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question