Answer the question
In order to leave comments, you need to log in
Duplicate entry '[email protected]' for key 'users_email_unique'?
Laravel 5.5 + AjaxRegister When registering users, sometimes I come across the following error in the logs:
at /var/www/game2/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '[email protected]' for key 'users_email_unique' at /var/www/game/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458)
use RegistersUsers;
protected $redirectTo = '/';
public function __construct()
{
$this->middleware('guest');
}
protected function validator(array $data)
{
$data['email'] = $data['email_reg'];
$data['password'] = $data['password_reg'];
$vaild = Validator::make($data, [
'name' => 'required|max:255|unique:users',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
if ($vaild->fails()) {
return json_encode($vaild->errors());
}
return true;
}
public function register(Request $request)
{
$v = $this->validator($request->all());
if (! is_bool($v)) {
return $v;
}
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
protected function create(array $data)
{
$data['email'] = $data['email_reg'];
$data['password'] = $data['password_reg'];
$avatar = Avatars::inRandomOrder()->first();
$referred_by = Cookie::get('referral');
$come_url = NULL;
if(null !== Cookie::get('come_url')){
$come_url = Cookie::get('come_url');
}
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
'come_url' => $come_url,
'last_login' => Carbon::now(),
'avatar' => $avatar->img,
'uniq' => md5($data['email'].$data['name'])
]);
}
protected function registered(Request $request, $user)
{
return "true";
}
Answer the question
In order to leave comments, you need to log in
Somewhere a test e-mail or a default e-mail [email protected] is sewn up. When some kind of verification fails or it is not specified, then it is substituted. But it already exists in the database and this field has a unique index so that there are no 2 identical e-mail addresses.
The output is stupid: remove the unique index from the field.
The output is normal: search for the project by searching for [email protected] and see where it comes from
public function register(Request $request)
{
$v = $this->validator($request->all());
return $this->registered($request, $user)
?: redirect($this->redirectPath());
[email protected]
called? Ajax or regular request? And that is, there is a suspicion that users see a white screen with the inscription "true"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question