Laravel 8.82 adds a required_array_keys
validation rule. The rule checks that all of the specified keys exist in an array.
Valid data that would pass the validation:
1$data = [ 2 'baz' => [ 3 'foo' => 'bar', 4 'fee' => 'faa', 5 'laa' => 'lee' 6 ], 7]; 8 9$rules = [10 'baz' => [11 'array',12 'required_array_keys:foo,fee,laa',13 ],14];15 16$validator = Validator::make($data, $rules);17$validator->passes(); // true
Invalid data that would fail the validation:
1$data = [ 2 'baz' => [ 3 'foo' => 'bar', 4 'fee' => 'faa', 5 ], 6]; 7 8$rules = [ 9 'baz' => [10 'array',11 'required_array_keys:foo,fee,laa',12 ],13];14 15$validator = Validator::make($data, $rules);16$validator->passes(); // false
Tip given by @AshAllenDesign