Skip to main content

Command Palette

Search for a command to run...

Laravel 12 Socialite Login With Google Account Example

How to Add Google Login using Socialite in Laravel 12

Updated
3 min read
Laravel 12 Socialite Login With Google Account Example
I

Experienced Web Developer | Laravel | PHP | jQuery | HTML | CSS I’m a skilled web developer with extensive experience building dynamic and responsive web applications using Laravel, PHP, jQuery, HTML, and CSS. I specialize in creating clean, scalable, and maintainable code, with a focus on performance and user experience. Whether it's developing RESTful APIs, building custom CMS features, or crafting responsive front-ends, I bring a problem-solving mindset and a passion for quality to every project.

In this guide, you’ll learn how to implement Google login in a Laravel 12 project using the Laravel Socialite package. Social logins provide a smoother experience for users by letting them sign in with accounts they already use—Google being the most common choice worldwide.

We’ll use Laravel’s built-in authentication scaffolding with Bootstrap to integrate Google OAuth. If you prefer, you could also set this up with Laravel Jetstream or Laravel Breeze, since both include support for third-party authentication. Laravel Socialite doesn’t just work with Google—it also supports popular providers like GitHub, Facebook, Twitter, and LinkedIn, giving you the flexibility to offer multiple login methods.

The process is straightforward: you’ll install and configure Socialite, create a Google Cloud OAuth client, define routes and a controller, and manage the login callback. Along the way, you’ll also see how to register users automatically and sign them in with their Google credentials.

By the end, you’ll have a fully functional Google login integration in Laravel 12 that you can directly apply to your own projects.

Steps For Laravel 12 Socialite Login with Google Account Example

  • Step 1: Install Laravel 12

  • Step 2: Install Laravel UI

  • Step 3: Install Laravel Socialite

  • Step 4: Configure Google OAuth Credentials

  • Step 5: Add google_id Column to Users Table

  • Step 6: Update User Model

  • Step 7: Create Controller for Google Login

  • Step 8: Create Route

  • Step 9: Add Google Login Button in Blade

  • Step 10: Run the Laravel Application

    Step 1: Install Laravel 12

    To get started, we need a fresh Laravel application. If you already have Laravel 12 set up on your system, you can move on to the next step. Otherwise, open your terminal and run the following command to create a new Laravel project:

      composer create-project laravel/laravel laravel-12-socialite-login-with-google
    

    Once the installation is complete, navigate into your project directory:

      cd laravel-12-socialite-login-with-google
    

    Now you’re ready to configure authentication with Socialite.

    Step 2: Install Laravel UI

    Before adding Google login with Socialite, let’s first configure the default authentication system in Laravel. This will generate the essential login, registration, and password reset functionality, along with a ready-to-use Bootstrap UI.

    Start by installing the Laravel UI package via Composer:

      composer require laravel/ui
    

    Next, run the command below to generate the Bootstrap-based authentication scaffolding:

      php artisan ui bootstrap --auth
    

    After that, install the frontend dependencies and compile the assets:

      npm install && npm run dev
    

    At this point, Laravel will:

    • Generate all the authentication routes (login, register, forgot password, etc.)

    • Provide a Bootstrap-powered frontend UI

    • Prepare your application for integrating Google login with Socialite

Note: If you’re already using Jetstream or Breeze, you don’t need to follow these Bootstrap UI steps, since those packages come with authentication out of the box.

Step 3: Install Laravel Socialite

Now that authentication scaffolding is ready, the next step is to bring in Laravel Socialite, the official package for handling OAuth authentication. Socialite provides a simple API to integrate with popular providers like Google, Facebook, Twitter, GitHub, LinkedIn, and more.

Run the following command to install Socialite via Composer:

    composer require laravel/socialite

Once installed, we’ll configure it to work with Google OAuth.