Socialite универсальный логин

Устанавливаем Socialite
composer require laravel/socialite
В файле services.php добавляем ключи зарегитрированные
   
'facebook' => [
  'client_id' => '468460863525722',
  'client_secret' => '10bbe2e3d0efacd81e5a4c8fe154fa15',
  'redirect' => 'http://localhost:8000/login/facebook/callback',
],
'twitter' => [
  'client_id' => 'yjZMljE9705tU5Hdf5tzZdFyYZm',
  'client_secret' => '6kNZAhYSDwy3xbDBRvPUz7qVSXWOfcHtUkE3V9lpfOvxp77Mjw',
  'redirect' => 'http://127.0.0.1:8000/login/twitter/callback',
],
'google' => [
  'client_id' => '134088073360-o9rl72ujgtga9amjl9m25ofmg4cuge7q.apps.googleusercontent.com',
  'client_secret' => 'getpQSxAQXwDquLn2jE7PvUTp',
  'redirect' => 'http://localhost:8000/login/google/callback',
],
Создаем миграцию дополнительной таблицы
Schema::create('social_providers', function (Blueprint $table) {
  $table->increments('id');
  $table->integer('user_id')->unsigned()->references('id')->on('users');
  $table->string('provider_id');
  $table->string('provider');
  $table->timestamps();
});
Создаем модель SocialProvider В модель добавляем
protected $fillable = ['provider_id','provider'];

function user(){
return $this->belongsTo(User::class);
}
в файле database.php изменить 'strict' => true, на 'strict' => false,
'mysql' => [
  'driver' => 'mysql',
  'host' => env('DB_HOST', '127.0.0.1'),
  'port' => env('DB_PORT', '3306'),
  'database' => env('DB_DATABASE', 'forge'),
  'username' => env('DB_USERNAME', 'forge'),
  'password' => env('DB_PASSWORD', ''),
  'unix_socket' => env('DB_SOCKET', ''),
  'charset' => 'utf8mb4',
  'collation' => 'utf8mb4_unicode_ci',
  'prefix' => '',
  'strict' => false,
  'engine' => null,
],
В контролере LoginController
use Socialite;
use App\SocialProvider;
/**
* Redirect the user to the Social authentication page.
*
* @return Response
*/
public function redirectToProvider($provider){
  return Socialite::driver($provider)->redirect();
}

/**
* Obtain the user information from Social.
*
* @return Response
*/
public function handleProviderCallback($provider){  
  try
  {
    $socialUser = Socialite::driver($provider)->user();
  }
  catch(\Exception $e)
  {
    return redirect('/');
  }
  // check if we have logged provider
  $socialProvider = SocialProvider::where('provider_id',$socialUser->getid())->first();
  if(!$socialProvider)
  {
  //create a new user and provider
    $user = User::firstOrCreate(
      ['email' => $socialUser->getEmail()],
      ['name' => $socialUser->getName()]
    );
    $user->socialProviders()->create(
      ['provider_id' => $socialUser->getId(), 'provider' => $provider]
    );
  }else{
    $user = $socialProvider->user;
  }
  auth()->login($user);
  return redirect('/home');
}
В web.php добавить строки
Route::get('login/{provider}', 'Auth\LoginController@redirectToProvider');
Route::get('login/{provider}/callback', 'Auth\LoginController@handleProviderCallback');