Laravel 7/6 Socialite Google Login Example

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

In this Login with google in Laravel 7/6 example tutorial I’ll show you how to integrate google login in laravel 7/6 using socialite package. Integrating google login in Laravel 7/6 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 7/6 Socialite Google Login Example

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

  • Install laravel App
  • Add Database Details
  • Install Socialite Package For Google Login
  • Create Google App
  • Set Google App Details
  • Add Routes
  • Generate Auth Files By Artisan
  • Create Controller
  • Add Socialite Google Login Button In Blade Views
  • Run Development Server

Step1: Install laravel App

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

Step 2: Add Database Details

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: Install Socialite Package For Google Login

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:

Step 4: Create Google App

Step 1:-
Visit Google Developer Console. And create a new project
Step 2:-
Please fill up the required information.
Step 3:-
After creating new project you need to select the created projects on the top menu. Then click on OAuth consent screen and select the given option according to your requirement:
Step 4:-
Next, you need to provide your website URL, privacy policy URL, etc.
Step 5:-
Click on left side menu credentials then select OAuth client ID.
Step 6:-
After that, the below form will be apper. Please select Web application from application type options. Once you have select Web application option, then one form will appear on web page. Here you have to define Name and you have also define Authorized redirect URIs field and lastly click on Create button.
Step 7:-
Once you have click on the create button, then you can get your Client ID and your client secret key.

Step 5: Add Google App Details

Now, we need to add google app details with redirect url. So, go to the config directory and open service.php file. And add the google client id, secret and redirect url in service.php file:

After that, open User.php model and add the following properties into User.php model file:

Now, go to app/database folder and open create_users_table.php. And add the following code into your create_users_table.php file:

Before you run PHP artisan migrate command, Navigate to go to app/providers folder and open AppServiceProvider.php file. And add the following code into your AppServiceProvider.php file:

Now, in this step we will create model and migration file. Please run the following command:

Step 6: Generate Auth File By Artisan

Install Laravel UI

Create Auth

NPM Install

Step 7: Add Routes

Now, you need to add routes in the web.php file. So navigate to routes folder and open web.php file. Then add the following routes into web.php file:

Step 8: Create Controller

Now, lets create a controller named GoogleLoginController using command given below –

Then go to app/controllers folder and open GoogleLoginController.php. And put the following code into your GoogleLoginController.php file:

Step 9: Add Socialite Google Login Button In Blade Views

Go to Resources/Views/Auth folder and open register.blade.php. Then add a laravel socialite google login button in register.blade.php file:

Next, go to Resources/Views/Auth folder and open login.blade.php. Then add a laravel socialite google login button in login.blade.php file:

Step 10: Run 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 7/6 Socialite Google Login Example and its application with practical example. I hope you will like this tutorial.