Where to check if email exists....

i'm a bit confused about VALIDATION in my app i need to create a model (technician) associated to the User model (ok) i have the technician email field sets as unique in the db when i create a technician with a non unique email, i need to send a notification now i get an error page with the sql statemnt of duplicated email in the form i have

Forms\Components\TextInput::make('email')
->email()
->required()
->unique()
->maxLength(255),

Forms\Components\TextInput::make('email')
->email()
->required()
->unique()
->maxLength(255),
is not enough?
8 Replies
Soundmit
Soundmit4mo ago
also this doesn't works

Forms\Components\TextInput::make('email')
->email()
->required()
->unique(Rule::exists('technicians', 'email'))
->maxLength(255),

Forms\Components\TextInput::make('email')
->email()
->required()
->unique(Rule::exists('technicians', 'email'))
->maxLength(255),
I'm watching some videos, and in all of them, when validation is enabled, a red message appears. I can't seem to do it.
toeknee
toeknee4mo ago
Forms\Components\TextInput::make('email')
->email()
->required()
->unique(ignoreRecord: true)
->maxLength(255),
Forms\Components\TextInput::make('email')
->email()
->required()
->unique(ignoreRecord: true)
->maxLength(255),
Soundmit
Soundmit4mo ago
yes, i saw this solution but the problem ssems thah validation is not fired if i have a technician in the db with email tec@example.com when i type tec@ i'm expecting a red flag "hey this email already exists"
toeknee
toeknee4mo ago
If that is the case, you will be mounting the form incorrect. Please provide the whole page code.
Soundmit
Soundmit4mo ago
ah ok, wait, now it works after i click on the button
Soundmit
Soundmit4mo ago
also with the ignoreRecord: true active, i can't update the record
toeknee
toeknee4mo ago
ignoreRecord: true means it ignores this record. Are you sure you don't have duplicated emails in the database already