File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,30 @@ between all of the rows in your user table:
103
103
}
104
104
}
105
105
106
+ // src/Form/Type/UserType.php
107
+ namespace App\Form\Type;
108
+
109
+ // ...
110
+ // DON'T forget the following use statement!!!
111
+ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
112
+
113
+ use Symfony\Component\Validator\Constraints as Assert;
114
+
115
+ class UserType extends AbstractType
116
+ {
117
+ // ...
118
+
119
+ public function configureOptions(OptionsResolver $resolver): void
120
+ {
121
+ $resolver->setDefaults([
122
+ 'data_class' => User::class,
123
+ 'constraints' => [
124
+ new UniqueEntity(fields: ['email']),
125
+ ]
126
+ ]);
127
+ }
128
+ }
129
+
106
130
.. caution ::
107
131
108
132
This constraint doesn't provide any protection against `race conditions `_.
You can’t perform that action at this time.
0 commit comments