Hi guys I need a little help here, I just made an auth controller with Laravel Socialite. First time I just retrieve the name and email data, and then I try to to retrieve the gender but it comes with an error that says
Undefined property: Laravel\Socialite\Two\User::$gender
Someone please help me to solve my problem, oh yeah my web still in development mode but I think it's not a problem because in facebook developer documentation said I still have access to basic information like first name, last name, profile picture, gender and age range.
Controller Source Code:
public function redirectToProvider()
{
return Socialite::driver('facebook')->redirect();
}
public function handleProviderCallback()
{
try {
$user = Socialite::driver('facebook')->user();
} catch (Exception $e) {
return Redirect::to('login/facebook');
}
$authUser = $this->findOrCreateUser($user);
Auth::login($authUser, true);
return Redirect::to('home');
}
private function findOrCreateUser($fbUser)
{
if ($authUser = User::where('email', $fbUser->email)->first()) {
return $authUser;
}
$role = "member";
return User::create([
'firstname' => $fbUser->name,
'email' => $fbUser->email,
'gender' => $fbUser->gender,
'role' => $role
]);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire