只需按照文件進行操作。
https://symfony.com/doc/5.3/reference/constraints/Callback.html
#class Author { // ... private int $field = 1; private string $otherField; /** * @Assert\Callback */ public function validate(ExecutionContextInterface $context, mixed $payload): void { if ($this->field > 1 && $this->otherField != '') { $context->buildViolation('Your validation message') ->atPath('toherField') ->addViolation(); } } }