0

I validate an array in laravel controller and receive message by using $errors->first('field_name') or $errors or $errors->has('field_name). Now the problem is, I validate an array named vaccine_certificate and I can not receive the error message. Actually I receive the message when show all erros at once. but I want to show it with it's input area. How can I solve it?

$this->validate($request, [
        'name' => 'required',
        'employee_no' => 'required',
         'vaccine_certificate.*' => 'image|mimes:png,jpg|max:2048|dimensions:max_height=200,max_width=200',
        //'expertise' => 'required',
    ]);

Input field looks like

<div class="col-6 form-group">
                    <label class="control-label " for="vaccine_certificate"><h5 class="h6">Vaccine Certificate <small>(<2mb,png,jpg) </small> </h5></label>
                    <input class="form-control" type="file" name="vaccine_certificate[]" id="vaccine_certificate" multiple/>
                    @if ($errors->has('vaccine_certificate'))
                    <p id="employee_no_checker_message" class="text-danger p-2" onload="changeInputBorderColor('vaccine_certificate')"> {{ $errors->first('vaccine_certificate') }}</p>
                    @endif
                    
                </div>

1 Answer 1

1

You can use and see all errors in the error bag of form.

$errors->all()

However, as far as I can see there is no "required" in vaccine_certificate, and your rule is vaccine_certificate.*, that means it should be an array. If you make it vaccine_certificate and required like you did in the name field you can see the error message.

If you need to use array, you can use:

$errors->first('vaccine_certificate.*') 

Since it is not "required" it will not throw an error and you can not see it in the $errors variable.

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

Comments

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.