I am using Laravel Socialite for google login all the scoialite functions are working fine and data is being added to the database(phpmyadmin) except for the provider_id which function is getId() which is also working fine but data is not inserted in Db.
public function handleProviderCallback()
{
try{
$socialUser = Socialite::driver('google')->user();
}catch(Exception $e){
redirect('/');
}
$socialProvider = SocialProvider::where('provider_id', $socialUser->getId())->first();
if(!$socialProvider){
//create new user
$user = User::firstOrCreate(
['email' => $socialUser->getEmail()],
['name' => $socialUser->getName()]
);
$user->socialProviders()->create(
['provider_id' => $socialUser->getId() , 'provider' => 'google']
);
}
else{
$user = $socialProvider->user;
}
auth()->login($user);
return redirect('/home');
//return $socialUser->getId();
}
'provider_id'
must be the protected $fillable
array on the SocialProvider
model if you want to pass it in the array to SocialProvider->create(...)
.