skip to Main Content

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

2

Answers


  1. $validator = Validator::make($request->input('data_attributes'), [
                
           '*.nic' => 'required|max:9'
                
    ]);
    Login or Signup to reply.
  2. 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",
    ]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search