Home - Scripts - Website Development

  • 10 September 2025

Implement Google Login in Laravel

by Sunil M. 3 minute read 12 views

Optimizing SEO titles, meta tags and Open Graph tags in Next.js improves visibility, improves click-through rates and boosts rankings in web development.

Key Points

  • 73% of users prefer Google Login, reducing password issues and enhancing overall account security.
  • Websites with Google OAuth see 64% higher login success compared to traditional email methods.
  • Google Login improves retention by 50%, making Laravel apps more user-friendly and secure.

Google Login is one of the most popular authentication methods used on web apps. It enables users to sign in with their Google account, providing both security and a seamless login experience.

This guide takes you through the step-by-step process of integrating Google OAuth into a Laravel app. By the end, you’ll learn how to configure Google APIs, set up Laravel for Google authentication, and securely manage user login.

In modern mobile app and website development, user authentication is crucial. From eCommerce platforms to SaaS dashboards, integrating Google Login enhances security and simplifies sign-up and login processes for users.

Step 1: Configure Google Console

To use Google OAuth in Laravel, you must first set up credentials in the Google Developers Console.

Steps to Configure Google Console:

1. Open the Google Developer Console and set up a new project.

2. Navigate to APIs & Services → Credentials.

3. Set up the OAuth Consent Screen by entering information such as application name, user type, and authorized domains.

Create new credentials:

  • Select OAuth Client ID
  • Application type: Web Application
  • Add Authorized redirect URIs (example: http://localhost:8000/auth/google/callback)

4. Copy the Client ID and Client Secret — you’ll need them for your Laravel project.

Step 2: Install Laravel Socialite

To add Google Login to Laravel, we will use Laravel Socialite, which simplifies OAuth authentication.

Run the following command in your Laravel project:

                                        composer require laravel/socialite

Next, register the Socialite service provider (if you’re using Laravel < 5.5, otherwise it’s auto-discovered):
'providers' => [
    Laravel\Socialite\SocialiteServiceProvider::class,
],
'aliases' => [
    'Socialite' => Laravel\Socialite\Facades\Socialite::class,
],
                                    

Step 3: Configure Google Client in Laravel

Add your Google Client credentials to the .env file:

                                        GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URI=http://localhost:8000/auth/google/callback
                                    

Then, update config/services.php:

                                        'google' => [
    'client_id' => env('GOOGLE_CLIENT_ID'),
    'client_secret' => env('GOOGLE_CLIENT_SECRET'),
    'redirect' => env('GOOGLE_REDIRECT_URI'),
],
                                    

Step 4: Create Routes and Controller

Now, define routes in your web.php:

                                        use App\Http\Controllers\GoogleController;

Route::get('auth/google', [GoogleController::class, 'redirectToGoogle']);
Route::get('auth/google/callback', [GoogleController::class, 'handleGoogleCallback']);
                                    

Create a controller GoogleController.php:

                                        namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Laravel\Socialite\Facades\Socialite;
use App\Models\User;
use Illuminate\Support\Facades\Auth;

class GoogleController extends Controller
{
    public function redirectToGoogle()
    {
        return Socialite::driver('google')->redirect();
    }

    public function handleGoogleCallback()
    {
        try {
            $googleUser = Socialite::driver('google')->stateless()->user();

            $user = User::updateOrCreate(
                ['email' => $googleUser->getEmail()],
                [
                    'name' => $googleUser->getName(),
                    'google_id' => $googleUser->getId(),
                    'avatar' => $googleUser->getAvatar(),
                    'password' => bcrypt(str()->random(16)),
                ]
            );

            Auth::login($user);

            return redirect('/dashboard'); // Redirect after login
        } catch (\Exception $e) {
            return redirect('/login')->with('error', 'Something went wrong!');
        }
    }
}

Make sure your users table has a google_id column. Run a migration if necessary:
php artisan make:migration add_google_id_to_users_table --table=users
Inside the migration:
public function up()
{
    Schema::table('users', function (Blueprint $table) {
        $table->string('google_id')->nullable();
        $table->string('avatar')->nullable();
    });
}
                                    

Run migration:

                                        php artisan migrate
                                    

Step 5: Add Google Login Button in Blade

In your login page (login.blade.php), add a Google Login button:

                                        <a href="{{ url('auth/google') }}" class="btn btn-danger">
   <i class="fa fa-google"></i> Login with Google
</a>
                                    

Step 6: Test and Deploy

  1. Run your Laravel server:

                                        php artisan serve
                                    

2. Go to http://localhost:8000/login and click Login with Google.

3. Authenticate with your Google account.

4. You should be redirected to /dashboard as a logged-in user.

When deploying, update the Google OAuth redirect URI in the Google Console to match your production domain.

Why Google Login Matters in Web and Mobile App Development

In today’s digital world, secure authentication is crucial for both web and mobile app development. Google Login provides:

  • Reduced Password Fatigue – Users don’t have to remember multiple accounts.
  • Improved Security – OAuth reduces risks of password leaks.
  • Higher Engagement – Easy logins encourage users to stay active.

At Digittrix, we develop secure and scalable web applications using Laravel. Whether you need custom authentication or full web and app development, our experts can create solutions tailored to your business.

If you’re interested in adding Google Login to your Laravel project or developing a custom web or mobile app, contact us today!

Tech Stack & Version

Frontend

  • HTML
  • CSS
  • JavaScript

Backend

  • Laravel Framework (PHP)
  • MySQL
  • PostgreSQL

Deployment

  • DigitalOcean
  • AWS
  • Linode

img

©2025Digittrix Infotech Private Limited , All rights reserved.