简体   繁体   中英

How to validate input name array in Laravel 5.5?

This is my input with start_date[value] :

<input type="text" class="form-control" id="inputSuccess2" placeholder="" name="start_date[value]">

This is my validation:

$validator = Validator::make($data, [
        'type'        => 'required|string',
        'def_fields'  => 'required|array',
        'def_filters' => 'required|array',
        'start_date[value]'  => 'required|array',
        'end_date[value]'    => 'required|array',
    ],[
        'def_fields.required'  => 'Report field is required',
    ]);

So far I did this:
start_date[value]
start_date.*
start_date.*.value

All of them seems to be not working.

You misunderstood start_date.value to put rules against and apply rule as array it would be just numeric or alpha_numeric not array , so try like

start_date.value => "required|numeric",

Or with array or min 1 element in array

start_date => "required|array|min:1"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM