1

For example, I have a password reminder form. How add annotation for email existence in database validation, for example @Assert\Exists.

class PasswordRemindRequest
{
    /**
     * @Assert\NotBlank
     * @Assert\Email
     */
    private $email;

    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    public function getEmail()
    {
        return $this->$email;
    }
}
Mikhail Prosalov
  • 4,155
  • 4
  • 29
  • 41
pietrach
  • 47
  • 1
  • 8
  • 1
    You need to write your custom validator https://symfony.com/doc/current/validation/custom_constraint.html where to check if email exists or not in database. – GasKa Mar 14 '19 at 09:23
  • Or use callback constraints => https://symfony.com/doc/current/reference/constraints/Callback.html – rebru Mar 14 '19 at 09:25
  • OK, thanks, I will write custom constraint. I thought it could be solved differently. Laravel has it better solved – pietrach Mar 14 '19 at 09:31
  • @Alex => @Assert\Exists doesn't exist in Symfony. I write this as example – pietrach Mar 14 '19 at 10:11

0 Answers0