When I'm using Symfony v5.1 array of collection validation I got a strange response.
This is my code
$constraint = new Assert\Collection([
'email' => new Assert\Email(),
'password' => new Assert\Length(['min' => 60]),
]);
$violations = $validator->validate($request->request->all() , $constraint);
foreach($violations as $violation)
{
$errors[] = [$violation->getPropertyPath() => $violation->getMessage()];
}
dd($errors);
and this is the result I got:
array:5 [
0 => array:1 [
"[password]" => "This value is too short. It should have 60 characters or more."
]
1 => array:1 [
"[name]" => "This field was not expected."
]
2 => array:1 [
"[phone_number]" => "This field was not expected."
]
3 => array:1 [
"[username]" => "This field was not expected."
]
4 => array:1 [
"[role_id]" => "This field was not expected."
]
]
so I'm wondering why the name of the input is swapping in array[] [name]
so is there is a wrong something I did?
And why Symfony is focused on entity validation and not on the request like Laravel framework?