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.
This isn't a EA question. But to answer it, you have to set it on Entity level. Like this:
#[UniqueEntity('policyNumber', message: 'Er is waarschijnlijk al een polis met dit nummer')]
How to validate my entity? I want to check if the
url
property is unique. So I did this: MyPost.php
entity:This is obviously not enough because my entity is not validated on create/update. So I tried to add a group like:
And call the group in the
PostGroupController.php
: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.