title: Client Error 500 in socialite google login laravel 5.8
body: <p>I have a laravel project that has been integrated with Facebook login, but if I use Google login, the page raises a client error that is 500 server errors</p>
  
  <p><strong>You can check on this website</strong> 
  <a href="https://indhri.asynchsolution.com" rel="nofollow noreferrer">https://indhri.asynchsolution.com</a>
  and login using google, 
  don't worry, I will delete the database immediately if this problem is resolved</p>
  
  <p>this is my SocialController.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers\Auth;
  
  use Illuminate\Http\Request;
  use App\Http\Controllers\Controller;
  use Laravel\Socialite\Facades\Socialite;
  use Illuminate\Support\Facades\Auth;
  use Spatie\Permission\Models\Role;
  use App\SocialAccount;
  use App\User;
  
  class SocialiteController extends Controller
  {
      public function redirectToProvider($provider)
      {
          return Socialite::driver($provider)-&gt;redirect();
      }
  
      public function handleProviderCallback($provider)
      {
          //$user = Socialite::driver($provider)-&gt;user();
           try {
              $user = Socialite::driver($provider)-&gt;user();
          } catch (Exception $e) {
              return redirect('/auth/login');
          }
          //dd($user);
          $authUser = $this-&gt;findOrCreateUser($user, $provider);
  
          Auth::login($authUser, true);
          return redirect('/personal');
      }
  
      public function findOrCreateUser($socialUser, $provider)
      {
          $socialAccount = SocialAccount::where('provider_id', $socialUser-&gt;getId())
                          -&gt;where('provider_name', $provider)
                          -&gt;first();
  
          if($socialAccount) {
              return $socialAccount-&gt;user;
          } else {
              $user = User::where('email', $socialUser-&gt;getEmail())-&gt;first();
  
              if(! $user) {
                  $user = User::create([
                      'username' =&gt; $socialUser-&gt;getName(),
                      'email' =&gt; $socialUser-&gt;getEmail()
  
                  ]);
                  $user-&gt;assignRole('Registered');
              }
  
              $user-&gt;socialAccounts()-&gt;create([
                  'provider_id' =&gt; $socialUser-&gt;getId(),
                  'provider_name' =&gt; $provider
              ]);
  
              return $user;
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/kXG4C.png" rel="nofollow noreferrer">This is the client error</a></p>
  
  <p><a href="https://i.stack.imgur.com/i7C0z.png" rel="nofollow noreferrer">this is error on Inspect</a></p>