Laravel Socialite first and last name
I've found that sometimes the user object won't contain the first and last names unless you specify you need those fields.
//get the driver and set desired fields
$driver = Socialite::driver('facebook')
->fields([
'name',
'first_name',
'last_name',
'email',
'gender',
'verified'
]);
// retrieve the user
$user = $driver->user();
then you can get the first name and last name like this
$user->user['first_name'] and $user->user['last_name']
Other stuff you can ask for:
https://developers.facebook.com/docs/graph-api/reference/user/
for google plus:
$user->firstname = $user->user['name']['givenName'];
$user->lastname = $user->user['name']['familyName'];
According to the dump of the $user
var you should be able to access the name values by doing:
$user->user['first_name']
and $user->user['last_name']
In linkedin you can get first and last name from provider like this.
$linkedinUser = $this->socialite->driver('linkedin')->user());
$attributes = [
'first_name' => $linkedinUser->user['firstName'],
'last_name' => $linkedinUser->user['lastName'],
'email' => $linkedinUser->email,
'avatar' => $linkedinUser->avatar,
'linkedin_id' => $linkedinUser->id
];