Home > Mobile >  Validating Arrays not working in laraval 9
Validating Arrays not working in laraval 9

Time:10-31

Validating Arrays not working in laraval 9.

Request as follows

array:2 [
  0 => array:4 [
    "nic" => "908110248V"
    "employee_id" => "1"
    "request_id" => "2"
    "schedule_training_id" => "1"
  ]
  1 => array:4 [
    "nic" => "962930898v"
    "employee_id" => "2"
    "request_id" => "1"
    "schedule_training_id" => "1"
  ]
]

validator code snipit as follows

        $validator = Validator::make($request->input('data_attributes'), [
            'data_attributes.*.nic' => 'required|max:9'
            
        ]);

CodePudding user response:

$validator = Validator::make($request->input('data_attributes'), [
            
       '*.nic' => 'required|max:9'
            
]);

CodePudding user response:

You should check the matrix as a whole and then start working with its elements, this is an example of what you should do:

$validator = Validator::make($request->input('data_attributes'), [
    "data_attributes"    => "required|array|min:3",
    "data_attributes.*"  => "required|string|distinct|min:3",
]);
  • Related