Laravel 7/6 Socialite Google Login Example

Laravel 7/6 Socialite Google Login Example

/Hello Laravel Developers and Beginner, In this laravel 7/6 social login tutorial – We would love to share with you, How can we implement google social login in your Laravel based project using laravel socialite package.

We will implement laravel google social login and illustrate each thing step by step. After we have completed this google login tutorial we will provide a live demo button so you can check easily how to work our laravel google social login example and you can try also your hand.

We will discuss how to add google social button in your laravel projects and how to simple authenticate (log in) users using the google Login button in our laravel app also we learn google register. We will show you each thing step by step.

Laravel Google Login Example

  • Install laravel Application
  • Setup Database
  • Download Socialite Package
  • Get Secrets from google
  • Make Route
  • Create Controller & Methods
  • Run Development Server
  • Conclusion

1. Install laravel Application

First, we need to download a laravel 6 fresh setup. Use the below command and download fresh new laravel setup :

composer create-project --prefer-dist laravel/laravel blog

2. Setup Database

After successfully install laravel 6 Application, Go to your project .env file and set up database credential :

DB_DATABASE=here your database name here
DB_USERNAME=here database username here
DB_PASSWORD=here database password here

3. Download Socialite Package

In this step, we will install the laravel socialite package for google login. you can use the below command and install this laravel socialite package :

composer require laravel/socialite

After successfully install socialite package, we need to configure the aliese and provider in config/app.php :

'providers' => [
// Other service providers…

'aliases' => [
// Other aliases…
'Socialite' => Laravel\Socialite\Facades\Socialite::class,

4. Get Secrets from google

First of all, We need to required CLIENT ID and CLIENT SECRET to add a social google login button in the laravel based project, let’s go to and create a new app. You will create the app with valid information.

After successfully create an app in Google and get credentials from Google dashboard, Set client id and client secret config/service.php file :

 'google' => [
    'client_id' => 'xxxx',
    'client_secret' => 'xxx',
    'redirect' => '',

Go to app/User.php and set fillable property put the below code here :

protected $fillable = [
'name', 'email', 'password', 'provider', 'provider_id'

Next step, Go to app/database/create_users_table.php and replace the below function here :

public function up()
Schema::create('users', function (Blueprint $table) {

Next step, we need to create new blade views for login, registration, forget the password and reset password. So visit this link for new laravel auth scaffolding.

Before we run PHP artisan migrate command go to app/providers/AppServiceProvider.php and put the below code :

use Illuminate\Support\Facades\Schema;
function boot()

Next, migrate the table using the below command :

php artisan migrate

5. Make Route

We will create two routes in the web.php file. Go to app/routes/web.php file and create two below routes here :

 Route::get('/auth/redirect/{provider}', 'SocialController@redirect');
Route::get('/callback/{provider}', 'SocialController@callback');

6. Create Controller

We need to create a controller name SocialController. Use the below command and create Controller :

php artisan make:controller SocialController

After successfully create controller go to app/controllers/SocialController.php and put the below code :


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Validator,Redirect,Response,File;
use Socialite;
use App\User;
class SocialController extends Controller
public function redirect($provider)
    return Socialite::driver($provider)->redirect();

public function callback($provider)
    $getInfo = Socialite::driver($provider)->user();
    $user = $this->createUser($getInfo,$provider);


    return redirect()->to('/home');

function createUser($getInfo,$provider){

 $user = User::where('provider_id', $getInfo->id)->first();

 if (!$user) {
     $user = User::create([
        'name'     => $getInfo->name,
        'email'    => $getInfo->email,
        'provider' => $provider,
        'provider_id' => $getInfo->id
  return $user;
Now We Add two buttons on the lara project for social google login. We have added this login button to login blade view and register blade view

In Project, go to Resources/Views/Auth/register.blade.php and add a google social login button :

<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<a href="{{ url('/auth/redirect/google') }}" class="btn btn-primary"><i class="fa fa-google"></i> Google</a>

In Project, go to Resources/Views/Auth/login.blade.php and add a google social login button :

<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<a href="{{ url('/auth/redirect/google') }}" class="btn btn-primary"><i class="fa fa-google"></i> Google</a>

7. Run Development Server

We need to start the development server. Use the PHP artisan serve command and start your server :

 php artisan serve

Now we are ready to run our LinkedIn login laravel 6 examples so run bellow command to quick run.
 Or direct hit in your browser


In this laravel social login tutorial, We have successfully added the login button on our Lara based project and using google button we have successfully login in the lara version 6 based application. our examples run quickly.

You may like

  1. Laravel Twitter Login Example Using Socialite Package
  2. Laravel Linkedin Login Tutorial With Live Demo
  3. Login with Facebook In Laravel 6 -Example
  4. Laravel Github Login Example
  5. Laravel Multi Auth( Authentication) Example Tutorial
  6. Laravel Custom Login Registration Example Tutorial
  7. Laravel REST API (Login & Registration) Authentication

If you have any questions or thoughts to share, use the comment form below to reach us.

AuthorTuts Make

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Javascript, JQuery, Laravel, Codeigniter, Vue JS, Angular JS, React Js, WordPress and Bootstrap from a starting stage.

2 replies to Laravel 7/6 Socialite Google Login Example

  1. how to get image avatar google

  2. Hello. Could you post a live-demo project on github?

Leave a Reply

Your email address will not be published. Required fields are marked *