Vishal Borade Vishal Borade - 1 year ago 116
PHP Question

laravel validate array fields

I am trying to validate array field using laravel validate functionality as follow

$this->validate($request,['prodActualQty' => 'required|numeric','actQty[]' => 'required'

my input file is:
<input class='form-control' type='text' name='actQty[]'>

It gives error if fields are blank but it still gives error even we fill the fields.

Answer Source

In Laravel 5.2 you can validate Form array elements using wildcards keyword.

So as per your situation you can either remove [] like below

$this->validate($request->all(), [
    'prodActualQty'     => 'required',
    'actQty'            => 'required'

Or use wildcard operator

$this->validate($request->all(), [
    'prodActualQty'     => 'required',
    'actQty.*'          => 'required'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download