mardi 27 octobre 2015

Laravel validator with a wildcard

i want to make a laravel validator that validates the the fields inside an un-named array ( 0,1,2,3 ) that is inside an array

so my array is like

array [ //the form data
  "items" => array:2 [ //the main array i want to validate
    0 => array:2 [ // the inner array that i want to validate its data
      "id" => "1"
      "quantity" => "1000"
     ]
    1 => array:2 [
     "id" => "1"
     "quantity" => "1000"
     ]
  // other fields of the form,
  ]

]

so what i want is something like

  $validator = Validator::make($request->all(), [
     'items.*.id' => 'required' //notice the star *
  ]);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire