douxian1939 2018-12-19 15:24
浏览 52

UpdateOrCreate无法更新一列

I`m coding Facebook Login with Laravel/Socialite.

I use UpdateOrCreate in the callback function, so if user does not exist, Laravel will create a new record, otherwise, will update some data on existing one.

public function handleProviderCallback()
    {
        $user = Socialite::driver('facebook')->stateless()->user();

        $key_token = $user->token;
        $key_fb = $user->getId();        
        $name = $user->getName();      
        $email = $user->getEmail(); 
        $url_photo = $user->getAvatar();   

        $user = User::updateOrCreate(
            [
                'email' => $email
            ],
            [   
                'name' => $name,
                'key_fb' => $key_fb,
                'url_photo' => $url_photo,
                'ḱey_token' => $key_token,
                'date_lastlogin' => \Carbon\Carbon::now(),
            ]
        );

        Auth::loginUsingId($user->id);
        return redirect('home');
}

But, be an Update or Create, the "key_token" is never inserted/updated. Mysql shows default value, Null. Other columns work fine.

I checked the value of key_token and its filled in all contexts. Also, the User Model $fillable array contains "key_token" .

protected $fillable = [
        'name', 'email', 'password', 'key_fb', 'url_photo', 'date_lastlogin', 'key_token',
    ];

I also have run the actual string (received token from FB) in the place of $key_token, but key_token continues to be filled with Null value.

(...)

 'url_photo' => $url_photo,
 'ḱey_token' => "IjasIJ937Jdsi823KJAndksu.......",
 'date_lastlogin' => \Carbon\Carbon::now(),

(...)

When echoing $user (from UpdateOrCreate return) , the value for key_token is Null

What to do in order to insert/update key_token?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 MATLAB中streamslice问题
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序