Laravel 8 Socialite Google Login Example Tutorial

In this tutorial you will learn about the Laravel 8 Socialite Google Login Example Tutorial and its application with practical example.

In this Laravel 8 Socialite Google Login Example Tutorial I’ll show you how to integrate google login in laravel 8 using socialite package. Integrating google login in Laravel 8 using socialite package is much easier. Allowing users to login with their social media accounts makes registration/login process much easier, it also encourages more users to register for your application.

Laravel 8 Socialite Google Login Example Tutorial

In this step by step tutorial, you will learn to integrate google login with your laravel 8 application. Please follow the steps give below:

  • Step 1 – Install Laravel 8 App
  • Step 2 – Configure Database With App
  • Step 3 – Configure Google App
  • Step 4 – Install Socialite & Configure
  • Step 5 – Add Field In Table Using Migration
  • Step 6 – Install Jetstream Auth
  • Step 7 – Make Routes
  • Step 8 – Create Google Login Controller By Command
  • Step 9 – Integrate Google Login Button In Login Page
  • Step 10 – Start Development Server

Step 1 – Install Laravel 8 App

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Step 2 – Configure Database With App

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3 – Configure Google App

In this step, we will configure Google app with this laravel app. So, open your laravel Google social login project in any text editor. Then navigate the config directory and open service.php file and add the client id, secret and callback url:

Step 4 – Install Socialite & Configure

In this step we will Install Socialite Package via Composer using following command:

Now, Navigate to config directory and open app.php file. Then add aliese and provider app.php:

Then add the Facade in config/app.php:

Step 5 – Add Field In Table Using Migration

Now, we will create migration to add social login field using following command:

After that, open the add_social_login_field.php file, which is found inside database/migration directory and add the following code into it:


After successfully add field in database table. Then add fillable property in User.php model, which is found inside app/Models/ directory:


After that, execute the following command on cmd to create tables into your selected database:

Step 6 – Install Jetstream Auth

In this step, install jetstream laravel auth scaffolding package with livewire. We have provided a complete guide in this Laravel 8 Auth Scaffolding using Jetstream Tutorial.

Step 7 – Make Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 8 – Create Google Login Controller By Command

In this step, run following command to create GoogleSocialiteController.php file:

Now, go to app/http/controllers directory and open GoogleSocialiteController.php file in any text editor. Then add the following code into GoogleSocialiteController.php file:

Step 9 – Integrate Google Login Button In Login Page

In this step, integrate google login button into login.blade.php file. So, open login.blade.php, which is found inside resources/views/auth/ directory:

Step 10 – Start Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Laravel 8 Socialite Google Login Example Tutorial and its application with practical example. I hope you will like this tutorial.