What You Will Build
By the end of this tutorial, you will have:
Google OAuth Login
Automatic user creation
Google profile data storage
Secure authentication flow
Production-ready structure
Extendable setup (Facebook, GitHub, etc.)
Requirements
Make sure you have the following installed:
PHP 8.2+
Laravel 12
MySQL / MariaDB
Composer
Google Account
Step 1: Create Google OAuth Credentials
1.1 Google Cloud Console Setup
Visit the Google Cloud Console:
👉 https://console.cloud.google.com/
Create a New Project
Navigate to APIs & Services → OAuth consent screen
Select External
Fill in required fields:
App name
User support email
Developer email
Save and continue
1.2 Create OAuth Client ID
Go to APIs & Services → Credentials
Click Create Credentials → OAuth Client ID
Application type: Web Application
Add Authorized Redirect URI:
Save and copy:
Client ID
Client Secret
Step 2: Install Laravel Socialite
Run the following command:
Laravel 12 supports package auto-discovery, so no manual configuration is required.
Step 3: Configure Google Service
Open the services configuration file:
📄 config/services.php
Step 4: Add Environment Variables
Open your .env file and add:
Step 5: Create Google-Ready Users Table
Update your users table migration:
📄 database/migrations/create_users_table.php
Run the migration:
Step 6: Create Google Authentication Controller
Generate the controller:
📄 app/Http/Controllers/Auth/GoogleAuthController.php
Step 7: Define Routes
📄 routes/web.php
Step 8: Add Google Login Button
📄 resources/views/auth/login.blade.php
Step 9: Protect Dashboard Route
Step 10: Run & Test the Application
Test Flow:
Open login page
Click Login with Google
Select Google account
Redirected to dashboard 🎉
Security Best Practices
Use HTTPS in production
Verify Google email address
Limit OAuth scopes
Auto-assign user roles
Enable account linking
Log authentication failures
Final Result
Google OAuth fully integrated
Automatic user creation
Secure login flow
Clean and scalable database
Laravel 12 compatible
Production-ready
Download Full Source Code
👉 GitHub:https://github.com/StarCodeKh/Login-with-Laravel-12-Using-Socialite

