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?