Selam benim sormak istediğim konu diyelim adam hem google hesabı ile girdi hemde linkedin hesabı ile ama emaili aynı (users_email_unique) o zaman ne yapabilirim. Her platforma göre colum mu açmak yoksa if ile kontrol mu yapmak gerek işte şu github hesabındakı email ile google hesabı ile girenin emaili aynıysa farklı bir şey yap diye. Ayrıca başka bir sorum farklı platform bilgilerini (id, token) tek user columnda mı saklamak gerek yoksa yine başka columlar mı gerek.
Kodlarım şunlar
Miigrate tablosu
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password')->nullable();
$table->string('github_id')->nullable();
$table->string('github_token')->nullable();
$table->string('github_refresh_token')->nullable();
$table->string('google_id')->nullable();
$table->string('google_token')->nullable();
$table->string('google_refresh_token')->nullable();
$table->string('google_picture')->nullable();
$table->rememberToken();
$table->timestamps();
});
Model
protected $fillable = [
'name',
'email',
'password',
'google_id',
'google_token',
'google_refresh_token',
'google_picture'
];
protected $hidden = [
'password',
'remember_token',
'github_id',
'github_token',
'github_refresh_token',
'google_id',
'google_token',
'google_refresh_token',
];
GithubController
public function LoginGithubController() {
return Socialite::driver('github')->redirect();
}
public function LoginGithubHandleController() {
$githubUser = Socialite::driver('github')->user();
$user = User::updateOrCreate([
'github_id' => $githubUser->id
],[
'name' => $githubUser->name,
'email' => $githubUser->email,
'github_token' => $githubUser->token,
'github_refresh_token' => $githubUser->refreshToken
]);
Auth::login($user);
return to_route('dashboard');
}
GoogleController
public function LoginGoogleController() {
return Socialite::driver('google')->redirect();
}
public function LoginGoogleHandleController() {
$googleUser = Socialite::driver('google')->user();
$user = User::updateOrCreate([
'google_id' => $googleUser->id
],[
'name' => $googleUser->name,
'email' => $googleUser->email,
'google_token' => $googleUser->token,
'google_refresh_token' => $googleUser->refreshToken,
'google_picture' => $googleUser->avatar
]);
Auth::login($user);
return to_route('dashboard');
}