Does anyone know how to validate nested input sets using the Laravel 4 validator?
I have a table with a set of line items, and each quantity field has the unique package id in square brackets in the name:
<input type="text" name="quantity[package_one]" />
<input type="text" name="quantity[package_two]" />
This results in a nested input array:
<?php
array(
'quantity' => array(
'package_one' => 3,
'package_two' => 12
)
);
Which is exactly what i want, but i'm unsure how to specify rules for these items using the validator class:
// Does not work :-(
Validator::make(Input::all(), array(
'quantity[package_one]' => 'numeric|required|min:1',
'quantity[package_two]' => 'numeric|required|min:1'
));
This does not seem to work, neither does nesting the rules under quantity
. Obviously there are workarounds to this like building a custom array of input yourself before passing it to the validator etc, but what i'd like to know is:
is there a native, "Laravel" way of handling nested input like this?
Thanks in advance, Dan.