I have a registration form with unique email validation. When I enter different character case, emails does not apply unique validation.
[email protected], [email protected], [email protected]
: Laravel unique validation is failed.
[email protected], [email protected], [email protected]
: Laravel unique validation is success.
Please check my code below and correct me. Email is storing as lowercase in database.
DB - Mongodb,
Framework - Laravel 5.5
jenssegers/laravel-mongodb is using to connect laravel and mongodb
RegisterController.php
protected function validator(array $data)
{
return Validator::make($data, [
'firstName' => 'required|string|max:255',
'lastName' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:user,usrEmail',
'password' => 'required|string|min:6|confirmed',
]);
}
User.php (Model)
public function setusrEmailAttribute($value)
{
$this->attributes['usrEmail'] = strtolower($value);
}
'email' => 'required|email|unique:user,usrEmail',
– Pluvial$data['email']
to lowercase. Maybe this is a problem with case sensitive. – Pluvialusers
table or auser
table? – Shiftless