MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

How to Login with Facebook, GOOGLE and twitter in Laravel?Part-1

How to Login with Facebook, GOOGLE and twitter in Laravel?

Step 1. Firstly, Create a new Project in Laravel, so open git bash. Write down the following command:-

$ composer create-project --prefer-dist laravel/laravel multilogin "5.8.*"Code language: JavaScript (javascript)
Git Bash running composer create-project laravel/laravel multilogin 5.8.* in htdocs

Step 2. Now, Move to project directory on git Bash, so write down the following command:-

$ cd multilogin
Git Bash after composer create-project for Laravel 5.8, then cd multilogin into the project folder

Step 3. Now, install the package of Socialite in git Bash use of composer which provides the interface to OAuth authentication with Google, Facebook, Twitter, and so on. Therefore, write down the following command:

$ composer require laravel/socialiteCode language: JavaScript (javascript)

Step 4. So, Create a Database for this and Go to XAMPP server->phpMyAdmin->Click New Database-> multilogin.

PhpMyAdmin Databases tab creating a new database named multilogin

Mysql Database connection Laravel

Step 5. Now, Go to .env file to set the project path and give the project DB_DATABASE name and DB_USERNAME name.

Laravel .env file in Sublime Text with APP_URL set to localhost/multilogin/public
Laravel .env file with DB_DATABASE set to multilogin and DB_USERNAME set to root

Step 6. Now, Go to config/database.php give the project DB_DATABASE name and DB_USERNAME name.

Config/database.php mysql settings with database multilogin and username root

Step 7.  So, Create the user authentication scaffolding and write down this command:

php artisan make:authCode language: CSS (css)
Git Bash running php artisan make:auth, showing authentication scaffolding generated successfully

Step 8.  Now, add credentials for the OAuth services in your project config/services.php configuration file. First, we’ll use the Facebook key here.

Config/services.php with a facebook entry for client_id, client_secret and callback redirect URL

Step 9. So, Go to this URL https://developers.facebook.com to generate client_id and client_secret of Facebook. Click Login Button and Log in with Facebook.

Facebook for Developers home page with Log In link and Developer Tools section
Facebook login page asking you to log in to continue to developers.facebook.com

Step 10. Click My Apps.

Facebook for Developers header after login, with the My Apps menu link

Step 11. After that, Click on Create App button.

Facebook for Developers My Apps page showing No Apps Created and a Create App button

Step 12. Now, Click the third one option or as your required.

Create an App ID dialog on Facebook with For Everything Else option selected

Step 13. Firstly, fill the App Name and Check on who can use your app according to your required.

Create an App ID form with display name multilogin, contact email and who can use the app
Facebook security check reCAPTCHA shown while creating the multilogin App ID

Step 14. Now, Add Product to your App and Click Set Up button of Facebbok Login.

Facebook app dashboard for multilogin on the Add a Product page with Facebook Login Set Up button

Step 15. Click on WWW .

Facebook for Developers Facebook Login Quickstart asking to pick a platform: iOS, Android, Web or Other

Step 16. Click on Settings -> Basic.

Facebook for Developers sidebar with Settings expanded and the Basic option for the multilogin app

Step 17. After that, Click on Facebook Login -> Settings.

Facebook for Developers sidebar with Facebook Login Settings open, showing Client OAuth Settings

Step 18. Redirect URI to Check and Save Changes.

Facebook Login Redirect URI Validator confirming the localhost auth/facebook/callback URL is valid

Step 19. Now, Set the path of the Project and Save changes within Settings/Base.

Facebook app Settings Basic page with the Website Site URL set to the localhost Facebook callback path

App ID

Step 20. Now, Copy App ID and Paste into Config/services.php file.

Sublime Text showing config/services.php with the facebook client_id line highlighted for the App ID

App Secret

Step 21. Copy App Secret and Paste into Config/services.php file.

Sublime Text showing config/services.php with the facebook client_secret line highlighted for the App Secret

Step 22. Now, Create a SocialProvider model, so write down the following command.

$ php artisan make:model -m SocialProvider
Terminal running php artisan make:model -m SocialProvider, with the model and migration created successfully

Step 23. Add user and provider id into the database/migrations/SocialProvider table file.

 $table->integer('user_id')->unsigned()->references{'id'}->on{'users'};
            $table->string('provider_id');
            $table->string('provider');Code language: PHP (php)
Social_providers migration with user_id, provider_id and provider columns added in Sublime Text

Step 24. Thereafter, Migrate the SocialProvider table into the MySQL database. Write the following command within git Base.

$ php artisan migrate

Step 25. Go to App/SocialProvider.php file and write down the following code:

SocialProvider.php model with fillable provider_id and provider fields and a belongsTo User relation

Step 26. Go to App/User.php file and write down the following code:


     function socialProviders()
    {
        return $this->hasMany(SocialProvider::class);
    }Code language: JavaScript (javascript)
User.php model with a socialProviders method returning hasMany SocialProvider

Step 27. So, Go to this URL https://laravel.com/docs/7.x/socialite#introduction to get the method asking for authentication and information.

Laravel 7.x Socialite docs with the redirectToProvider and handleProviderCallback example code highlighted

Step 28. Then, paste into app/Http/Controllers/Auth/RegisterController.php file.

public function redirectToProvider()
    {
        return Socialite::driver('facebook')->redirect();
    }
    public function handleProviderCallback()
    {
        $user = Socialite::driver('facebook')->user();
          return $user->getEmail();
    }Code language: PHP (php)
RegisterController.php with Facebook Socialite redirectToProvider and handleProviderCallback methods

Step 29. Go to resources/views/welcome.blade.php file and write down this following code:

Welcome.blade.php with a Facebook login link pointing to /auth/facebook added beside Login

Step 30. Then, go to routes/web.php file and define all these routes.

Route::get('auth/{provider}', 'Auth\RegisterController@redirectToProvider');
Route::get('auth/{provider}/callback', 'Auth\RegisterController@handleProviderCallback');
Code language: PHP (php)
Routes/web.php defining the auth/{provider} and auth/{provider}/callback routes to RegisterController

Step 31. After that, use Socialite and SocialProvider Class inside app/Http/Controllers/RegisterController.php file.

use Socialite;
use App\SocialProvider;Code language: PHP (php)
RegisterController.php in Sublime Text with use Socialite and use App\SocialProvider lines highlighted

Step 32. Set the password null in the database as well inside the database/migrations/users table.

 $table->string('password')->nullable();Code language: PHP (php)
Laravel users table migration in Sublime Text with password column set to nullable

Step 33. Before run your project, just clear the cache.

$ php artisan c:cache
Git Bash running php artisan c:cache, showing configuration cache cleared and cached successfully

Run the Project URL

Laravel welcome page with Login, Facebook and Register links at top right
Login with Facebook
Facebook permission dialog for the multilogin app with a Continue as Usha button
Continue
Laravel dashboard showing You are logged in! for user Usha Kiran after Facebook login
User Dashboard

Thanks

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.

Related Posts

Google Blogger Automation: Complete Guide to Blogger API, Claude Code, Codex and Playwright

Practical tutorial | API publishing, scheduled workflows, multi-blog management and XML theme deployment | November 2026 Featured image (1200 × 630 px): Blogger automation with API and…

Read More

Single Sign-On Implementations: Practical Comparison and Evaluation Guide

This guide expands a short 2015 link list of SSO tools into a practical DevOps reference. You will learn how SSO flows work, how to compare implementations, and how to validate integrations with real commands.

Read More

Complete Tutorial: JWT (JSON Web Token) & OIDC (OpenID Connect)

1. 🔎 What is JWT? Definition Structure 2. 🔎 What is OIDC? Definition Key OIDC Tokens 3. ❓ Why do we need them? JWT OIDC 4. ⚙️…

Read More

Laravel: oauth_access_tokens clean up process

using Laravel Passport—the oauth_access_tokens table balloons when tokens aren’t expiring, not being revoked on logout, or not being purged. Here’s a practical, safe cleanup + prevention plan…

Read More

Keyclock: A Identity & SSO tools

Keycloak: Identity & SSO Tool (IAM in one box) What it is Keycloak is an open-source Identity and Access Management (IAM) platform that provides Single Sign-On (SSO),…

Read More

Laravel: Complete Guide of Laravel Passport

Here’s a comprehensive, up-to-date step-by-step tutorial for setting up and using Laravel Passport (OAuth2 API authentication) with clear explanations, working code samples, and troubleshooting tips—suitable for local…

Read More