Answer the question
In order to leave comments, you need to log in
How to validate internal array in Symfony 4?
Hello! There is a request with something like this body
{
"subject": "subj",
"data": "text",
"toEmail": [
"sgs",
"3434"
]
}
$constraint = new Assert\Collection(
[
'fields' => [
'subject' => [
new Assert\NotBlank(),
new Assert\Type('string'),
new Assert\Length(['min' => 2, 'max' => 255])
],
'data' => [
new Assert\NotBlank(),
new Assert\Type('string'),
new Assert\Length(['min' => 2])
],
'toEmail' => [
new Assert\NotBlank(),
new Assert\Type('array')
]
]
]
);
$violations = $validator->validate($body, $constraint);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question