3

I have a case when i try to validate a property of an php PHP object, this property can be null but not empty string. Is it possible to do it with a single annotation like:

class JustAnObject
{
    /**
     * @Assert\NotBlankNullable
     */
     private $Property;
}

1 Answer 1

3

Yes it is possible in symfony 4.3 you can do:

namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class JustAnObject
{
    /**
     * @Assert\NotBlank(allowNull = true)
     */
    private $property;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.