profileRyan KesPGP keyI build stuffEmailGithubTwitterLast.fmMastodonMatrix

Groups support for Valid constraint

Introduction

As per Symfony 4.0 validation groups are supported for the Valid constraint.

Syntax

// src/AppBundle/Entity/Address.php
// ...
class Address
{
    /** @Assert\NotBlank(groups={"basic"}) */
    protected $street;

    /** @Assert\Length(max = 5) */
    protected $zipCode;
}

// src/AppBundle/Entity/Author.php
// ...
class Author
{
    /** @Assert\NotBlank */
    protected $firstName;

    /** @Assert\NotBlank */
    protected $lastName;

    /** @Assert\Valid(groups={"basic"}) */
    protected $address;
}