0

User Data is not saving to Database in Laravel 6. I am using socialite to save data to the database with the following code lines.

protected $fillable = [
    'email','name','password','username','picture'
];

In the login controller. I am able to fetch data from socialite correctly(I Checked).

$user = User::firstOrCreate(

          ['email'=> $social_user->getEmail()],
          ['username'=> $social_user->getName()],
          ['name'=> $social_user->getName()],
          ['picture'=> $social_user->getAvatar()],
          ['password'=> 'sdsdsdsad'],
          ['ip_address'=> '127.0.0.1'],


      );
Upasana Chauhan
  • 948
  • 1
  • 11
  • 32

3 Answers3

0

Try the following

// you may dump($social); to check if $social contains valid data before using it
$user = User::firstOrCreate(

          ['email'=> $social_user->getEmail()]
          [
           'username'=> $social_user->getName(),
           'name'=> $social_user->getName(),
           'picture'=> $social_user->getAvatar(),
           // Password Hash
           'password'=> bcrypt('sdsdsdsad'),
           'ip_address'=> '127.0.0.1']

);

Check FirstOrCreate Usage

Foued MOUSSI
  • 4,643
  • 3
  • 19
  • 39
  • 1
    edit `['email'=> $social_user->getEmail(),]` to `['email'=> $social_user->getEmail()],` you spelled `,` – STA Feb 15 '20 at 15:23
0

This works

$user = User::firstOrCreate(

    ['email'=> $social_user->getEmail(),
     'username'=> $social_user->getName(),
     'name'=> $social_user->getName(),
     'picture'=> $social_user->getAvatar(),
     'password'=> 'sdsdsdsad',
     'ip_address'=> '127.0.0.1'],    
);
Foued MOUSSI
  • 4,643
  • 3
  • 19
  • 39
Upasana Chauhan
  • 948
  • 1
  • 11
  • 32
0

In your Model you forget to add ip_address. So Your Model :

protected $fillable = [
    'email','name','password','username','picture','ip_address'
];

In your controller :

$user = User::firstOrCreate(
      ['email' => $social_user->getEmail()], 
      [
         'username'=> $social_user->getName(),
         'name'=> $social_user->getName(),
         'picture'=> $social_user->getAvatar(),
         'password'=> 'sdsdsdsad',
         'ip_address'=> '127.0.0.1'
      ]
);
STA
  • 30,729
  • 8
  • 45
  • 59