I have the following array returned from an API call and want to save values for "user.location.name" and others which are contained within the multidimensional response. Here is the edited response which shows the structure:
Laravel\Socialite\Two\User Object
(
[token] =>
[refreshToken] =>
[expiresIn] =>
[id] =>
[nickname] =>
[name] =>
[email] => l
[avatar] =>
[user] => Array
(
[emailAddress] =>
[firstName] =>
[formattedName] =>
[headline] =>
[id] =>
[industry] =>
[lastName] =>
[location] => Array
(
[country] =>
(
[code] =>
)
[name] => *****VALUE I WANT*****
)
[pictureUrl] =>
[positions] => Array
(
[_total] => 1
[values] => Array
(
[0] => Array
(
[company] => Array
(
[name] => *****VALUE I WANT*****
)
[id] =>
[isCurrent] =>
[location] => Array
(
[country] => Array
(
[code] =>
[name] =>
)
[name] =>
)
[startDate] => Array
(
[month] =>
[year] =>
)
[summary] =>
[title] =>
)
)
)
[publicProfileUrl] =>
[summary] =>
[avatar_original] =>
)
I'm then checking if a user already exists and then saving them in a database with the following function:
public function userFindOrCreate($linkedin_user)
{
$user = User::where('provider_id', $linkedin_user->id)->first();
if (!$user){
$user = new User;
$user->name = $linkedin_user->getName();
$user->email = $linkedin_user->getEmail();
$user->picture = $linkedin_user->getAvatar();
$user->provider_id = $linkedin_user->getId();
$user->access_token = $linkedin_user->token;
$user->linkedin = $linkedin_user->getRaw()['publicProfileUrl'];
$user->location = ?????
$user->company_name = ????
$user->save();
}
return $user;
}
How would I access the values shown as ******VALUE I WANT****** in the above code and save them to the new User? Dot notation doesn't work with getRaw() method so I can't get this to work (although it does work for things 1 layer deep such as publicProfileUrl).
I've also tried referencing
use Illuminate\Support\Arr;
and using
$user->location = Arr::get($linkedin_user, 'user.location.name')
although this isn't working either...