如果用户使用Facebook登录,我想将该信息存储在users表中,以便进一步使用该应用程序,但某些值不可见。
使用Facebook登录时,我使用此代码获取用户信息(导入“Kint”以显示这些值):
$user = Socialite::driver('facebook')->user();
s($user);
此脚本的输出:
Laravel\Socialite\Two\User (8) (
public token -> string (197) "facebook token .."
public id -> string (17) "user id .."
public nickname -> NULL
public name -> string (11) "my name"
public email -> string (21) "myname@mail.com"
public avatar -> string (69) "https://graph.facebook.com/v2.5/my_id/picture?type=normal"
public user -> array (6) [
'first_name' => string (5) "first name"
'last_name' => string (5) "last name"
'email' => string (21) "myname@mail.com"
'gender' => string (4) "male"
'verified' => bool TRUE
'id' => string (17) "my id"
]
public avatar_original -> string (68) "https://graph.facebook.com/v2.5/my_id/picture?width=1920"
)
我想使用此脚本将其中一些值放在表中:
DB::table('users')->insert(
['user_id' => array_get($user, 'id'),
'name' => array_get($user, 'name'),
'first_name' => array_get($user, 'user.first_name'),
'last_name' => array_get($user, 'user.last_name'),
'nickname' => array_get($user, 'nickname'),
'email' => array_get($user, 'email'),
'gender' => array_get($user, 'user.gender')]
);
返回的唯一值是“token”,“id”和“email”,如果我看到查询生成,则所有其他值都为空
有谁知道他们为什么是空的?谢谢
答案 0 :(得分:1)
它们是空的,因为你有一个实例是一个对象,而不是一个数组。您应该使用->
运算符来访问以下属性:
DB::table('users')->insert(
['user_id' => $user->id,
'name' => $user->name,
'first_name' => $user->user['first_name'],
'last_name' => $user->user['last_name'],
'nickname' => $user->nickname,
'email' => $user->email,
'gender' => $user->user['gender']]
);