Laravel社交名姓和姓氏 [英] Laravel Socialite first and last name

查看:88
本文介绍了Laravel社交名姓和姓氏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel的Socialite向应用程序添加社交身份验证.我可以分别检索全名,但不能分别检索名和姓.发生回调并由Socialite处理后,将成功检索用户.如果我要转储用户,我会从$user = this->social->driver('facebook')->user();回来,我得到以下信息:

I'm adding social authentication to an application using Laravel's Socialite. I can retrieve the full name but not the first and last names separately. After the callback happens and Socialite is handling it, the user is retrieved successfully. If I am to dump the user I get back from $user = this->social->driver('facebook')->user(); I get the following:

object(Laravel\Socialite\Two\User)#459 (8) {
     ["token" ]=> string(209) "{token}"
     ["id"] => string(17) "{socialID}"
     ["nickname"] => NULL
     ["name"] => string(14) "{Full Name}"
     ["email"] => string(19) "{Email address}"
     ["avatar"] => string(69) "https://graph.facebook.com/v2.4/{socialID}/picture?type=normal"
     ["user"] => array(6) {
        ["first_name"] => string(6) "{First name}"
        ["last_name"] => string(7) "{Last mame}"
        ["email"] => string(19) "{Email address}"
        ["gender"] => string(4) "male"
        ["verified"] => bool(true)
        ["id"] => string(17) "{socialID}"
    }
    ["avatar_original"] => string(68) "https://graph.facebook.com/v2.4/{socialID}/picture?width=1920"

}

我可以通过$user->name$user->email获得全名或电子邮件,但是我无法获得单独的名字和姓氏.我已经尝试过$user->first_name以及尝试转储$user->user数组,但是我看到的只是未定义的属性错误.

I can obtain the full name or email via $user->name or $user->email however, I can not get the separate first and last names. I have tried $user->first_name as well as trying to dump the $user->user array but all I see is undefined property errors.

我不想做奇怪的事情,例如当明显的分开的名字和姓氏存在时,从全名中提取出来,因为当中间名出现时,它会变得很丑陋.

I do not want to do something weird like extract it from the full name when the separate first and last name are clearly there as it can get ugly when middle names are present.

我已经绕过Google搜索了,很奇怪,没有人遇到这个问题.我是否缺少文档中的某些内容? 非常感谢任何有关如何从user数组检索名字和姓氏的建议.

I have Googled my way around and weirdly, nobody came across this issue. Am I missing something from the docs? Any suggestions on how to retrieve the first and last name from the user array are greatly appreciated.

推荐答案

根据$user var的转储,您应该可以通过以下方式访问名称值:

According to the dump of the $user var you should be able to access the name values by doing:

$user->user['first_name']$user->user['last_name']

这篇关于Laravel社交名姓和姓氏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆