I would like to create login form using facebook, google, and twitter accounts. First step, I can create them by using Socialite Package. Second step, I can get user's info and insert into MySQL Database. My problem is I login successfully using facebook account for the first time and then I logout. After that I login with google account instead. The error occurred like this:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'users_email_unique' (SQL: insert into `users` (`name`, `updated_at`, `created_at`) values (SrengKhorn, 2015-09-22 02:44:26, 2015-09-22 02:44:26))
And I found that if I delete previous record with the same username I can login with any of them without error. Do you know to resolve this problem?
Well. The logic is very simple. You are trying to insert a blank email. And yeah, not a matter of surprise, email is a unique field. A blank email cannot be inserted as it is being repeated. So just add the email while you are trying to log user in. You may use $user->email
. Just store that email. And while once again logging in, just check if the user already exists with the same email. If not, just put the values, else login the user.