1

I have an HTML form where users can upload multiple images. I'm looking for the solution to validate images before they are uploaded. I use following HTML tag:

<input id="images" multiple="multiple" name="images[]" type="file" accept="image/*">

For the validation I made RealEstateValidation request class. In the validation class I use rules method to define validation rules:

public function rules()
    {
        return [
              'area'=>'required',
              'number_of_rooms'=>'required',                 
              'address'=>'required'
        ];
    }

What should I add into the rules to validate images? For example I added 'images' => 'array|image|max:1000' line but it did not work? How can I fix this issue?

1 Answer 1

2

just do a small change:

public function rules()
{
    return [
          'area'=>'required',
          'number_of_rooms'=>'required',                 
          'address'=>'required'
          'images.*'=>'required|image'

    ];
}
Sign up to request clarification or add additional context in comments.

1 Comment

you can get error like this <span class="help-block">{{ $errors->first('images.0') }}</span>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.