Validating an entity in EasyAdmin

Viewed 7

How to validate my entity? I want to check if the url property is unique. So I did this: My Post.php entity:

use Symfony\Component\Validator\Constraints as Assert;
....
    #[ORM\Column(length: 255)]
    #[Assert\Unique]
    private ?string $url = null;
....

This is obviously not enough because my entity is not validated on create/update. So I tried to add a group like:

....
#[Assert\GroupSequence(['post_validation'])]
class Post
....

And call the group in the PostGroupController.php:

public function configureCrud(Crud $crud): Crud
    {
        return $crud
            ->setEntityLabelInSingular($this->translator->trans('post.post'))
            ->setEntityLabelInPlural($this->translator->trans('post.posts'))
            ->setSearchFields(['title'])
            ->setFormOptions(['validation_groups' => 'post_validation']);
    }

But this doesn't work either. By not working I mean that the record is saved/updated with not unique url. So what is wrong with this EasyAdmin validation or I am doing the things wrong ? P.S. I have the symfony validator installed.

0 Answers
Related