Search code examples
laravellaravel-5laravel-5.5

Check if error bag of input array has a particular index


Version of Laravel: 5.5.*

Form

<input name="name[]"/>
<input name="name[]"/>
<input name="name[]"/>

Validation is put in an error bag.

If I have an error on the second input, I will get an array of error messages with

name.1 => "error message"

What I want to do is check if the bag has any error for the index name.i

How can I do that?


Solution

  • You can check the error at the index i with

    $errors->bagname->has('*.i')