я использую socialite, чтобы дать пользователям возможность войти через Facebook или github.но когда пользователь входит в систему с Facebook и после этого с помощью GitHub, создаются 2 отдельные учетные записи.Итак, мой вопрос, есть ли способ объединить эти два аккаунта в один?например, если пользователь, который вошел в систему с помощью Facebook, использует тот же адрес электронной почты, чтобы войти в систему с помощью github, новая учетная запись не будет создана, и они просто войдут в систему
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('profile');
$table->string('slug');
$table->string('provider_id');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
код входа / регистрации
/**
* Redirect the user to the provider authentication page.
*
* @return Response
*/
public function redirectToProvider($provider)
{
return Socialite::driver($provider)->redirect();
}
/**
* Obtain the user information from the provider.
*
* @return Response
*/
public function handleProviderCallback($provider)
{
$SocialUser = Socialite::driver($provider)->stateless()->user();
$user = $this -> findOrCreateUser($SocialUser,$provider);
auth()->login($user,true);
return redirect('/');
}
protected function findOrCreateUser($SocialUser,$provider)
{
$user = User::firstOrNew(['provider_id' => $SocialUser->id]);
if ($user->exists) return $user;
$user->fill([
'name' => $SocialUser->nickname?:$SocialUser->name,
'slug' => str_slug($SocialUser->nickname?:$SocialUser->name).'-'.uniqid(),
'email' => $SocialUser->email,
'avatar' => $SocialUser->avatar,
'profile' => Hash::make('no pic'),
'password' => Hash::make('no need for password token based'),
// 'website' => 'add a website',
// 'github_profile' => 'add github profile',
'email_notifications' => 1
])->save();
$user->assignRole('user');
\Mail::to($user)->send(new Welcome($user));
session()->flash('message','Welcome to '.config('app.name').' '.$user->name);
return $user;
}
}