I'm integrating Facebook login in my web app, but I get this error:
ErrorException in SessionGuard.php line 407: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, string given, called in /Applications/XAMPP/xamppfiles/htdocs/shop/vendor/laravel/framework/src/Illuminate/Auth/AuthManager.php on line 294 and defined
I saw that the issue is when I create the new user:
public function findOrCreateUser($user, $provider)
{
$authUser = User::where('provider_id', $user->id)->first();
// if user exist login
if ($authUser) {
return $authUser;
}
// if user don't exist - Create new user
$test = DB::table('users')->insert([
'name' => $user->name,
'email' => $user->email,
'provider' => $provider,
'provider_id' => $user->id
]);
return 'Hello'; // just try if it work!
}
User is created correctly but I get the error above. I can't see my message "Hello". If I replace the create method like this:
return User::create([
'name' => $user->name,
'email' => $user->email,
'provider' => $provider,
'provider_id' => $user->id
]);
it works well. But I don't want stop after create user; I would like return another view.
There is several ways how to insert new row into table in laravel.
One way to do it is
User::create([
'name' => $user->name,
'email' => $user->email,
'provider' => $provider,
'provider_id' => $user->id
]);
return view('your_view');
But you need to have this in your model (for mass assignment)
protected $fillable = ['name','email','provider','provider_id'];
Other way to insert new row is next
$user_database = new User;
$user_database->name = $user->name;
$user_database->email = $user->email;
$user_database->provider = $provider;
$user_database->provider_id = $user->id;
$user_database->save();
return view('your_view');
Hope it helps you. For more additional help check official documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With