Your Location is: Home > Symfony

@Assert\NotBlank not recognised

From: French View: 1100 Jean-Pierre Mena 

Question

I am actually following the Chapter 14 of the Symfony 5.0 fast track. I defined the Assert annotation in the use statement :

use Symdony\Component\Validator\Constraints as Assert;

And in the Comment entity: I add the @Assert\NotBlank for the author field which gives;

/**
     * @ORM\Column(type="string", length=255)
     * @Assert\NotBlank
     */
    private $author;
  • When displayin the comments page, I get the following error:
[Semantical Error] The annotation "@Symdony\Component\Validator\Constraints\NotBlank" in property App\Entity\Comment::$author was never imported. Did you maybe forget to add a "use" statement for this annotation?
  • I don't understand the point as "symfony/validator": "5.0.",* has already been imported.

  • Any Idea ?

Thanks in advance for your help...

Best answer

use Symdony\Component\Validator\Constraints\NotBlank;

replacing Symdony with Symfony should do it

Another answer

I had the same problem with NelmioApiDoc bundle. What worked for me was to delete the vendor and composer.lock and reinstall all the bundles. Also you can try importing each class.

use Symdony\Component\Validator\Constraints\NotBlank;

Hope it helps. Take care