Skip to content
Advertisement

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'
],$messages);

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.

Advertisement

Answer

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'
]);
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement