I am a new PHP
coder.
I use Facebook login as a third party.
I am successfully able to get some user data from Facebook API
, but I got some error in creating the new user of the DB.
password dosent have a default value
What data should be inserted in the password field?
facebookcallback function
public function handleFacebookCallback()
{
try {
$user = Socialite::driver('facebook')->user();
$create['name'] = $user->getName();
$create['email'] = $user->getEmail();
$create['facebook_id'] = $user->getId();
$creaet['memberId'] = $user->getId();
$userModel = new User;
$createdUser = $userModel->addNew($create);
Auth::loginUsingId($createdUser->id);
return redirect()->route('/loginsucces');
} catch (Exception $e) {
return redirect('/');
}
}
I found some information on the Internet, and I know i got the accessToken in the facebook callback. Then i use this token
Socialite::driver(‘facebook’)->user();
to ask facebook to get some user information.
Then the web login process with fb checks whether the database has user data.
If no, new user data is created.
However, the error is happened in the create.
OMG !!!! I didnt insert any data of the password field.
I cant find any answer on the internet.
Have anyone can help me to resolve this problem?
2
Answers
In you users database migration file, make password field nullable. Like this
That would not show error on password anymore because we have made it optional when creating user with nullable.
Hope this helps you.
Try to pass insert password when u created new user from facebook. And make sure your database column password allow null value, so new user created withouy password