I have a form that has an input "array" that, when submitted, is validated using Laravel's Validator.
The validation is working as expected, applying the rule to every array element, and returning a MessageBag of errors accordingly.
The problem: the MessageBag makes no reference to the related index of the array. Is there a way (besides defining a rule for each possible index of the array) to make Laravel reference the related input array index?
Sample HTML
<input name="something[]" type="text" />
<input name="something[]" type="text" />
<input name="something[]" type="text" />
...
Sample validator
Validator::make
(
Input::all(),
array
(
"something" => array("required", "exists:somewhere")
)
);
Sample MessageBag after validation (no reference to the input array index)
object(Illuminate\Support\MessageBag)#150 (2)
{
["messages":protected]=> array(6)
{
["something"]=> array(1)
{
[0]=> string(26) "Some error message"
}
}
...
}
<input>element, so I can tie the error to a specific form element. Right now Laravel only references the element's name ("something") which could be any of the<input>'s - Telmo Marques<input name="something[]" type="text">? Couldn't you use something like<input name="something_1[]" type="text"><input name="something_2[]" type="text">...? Can you tell me what are you exactly intending to do maybe I can give you a better idea! - Waiyl Karim[]as arrays. If I add "_1", "_2", etc to the name I'd have to create specific Laravel validator rules for each input (that's what I'm trying to avoid). - Telmo Marques