public function index(): string
{
// Extend the user guide case and add one more layer.
$requestData = [
'contacts' => [
'name' => 'Joe Smith',
'just' => [
'friends' => [
[
'name' => 'Fred Flinstone',
],
[
'name' => 'Wilma',
],
],
],
],
];
$this->validator = \Config\Services::validation();
$this->validator->setRules([
'contacts.*.name' => 'required|max_length[1]',
]);
dd(
$this->validator->run($requestData),
$this->validator->getErrors(),
$this->validator->getValidated()
);
}
$this->validator->run(...) boolean false
⧉⌕$this->validator->getErrors() array (2)
⇄contacts.just.friends.0.name => string (63) "The contacts.*.name field cannot exceed 1 characters in length."
⇄contacts.just.friends.1.name => string (63) "The contacts.*.name field cannot exceed 1 characters in length."
$this->validator->getValidated() array (0)
⧉ Called from .../app/Controllers/Home.php:34 [dd()]
From #8079 (comment)
The
namekey iscontacts.just.friends.*.name, notcontacts.*.name.