How to Login with Facebook Account Using Socialite Package In Laravel?

Updated 19 May 2023

Hello Everyone, so in this article we will learn how to login with a Facebook account in Laravel application using the Socialite package.

Login with social media accounts is a simple process that improves the user experience, you got more people to connect with your website because most people do not want to fill out sign-up or sign-in forms. If there log in with social media like Facebook then it becomes awesome.

we are creating a simple feature to log in with a Facebook account in the Laravel application. Authentication user interface templates are required for this tutorial, and we are using Laravel Jetstream to streamline the Authentication UI process.

So if you want to also implement login with a Facebook account then I will help you with step-by-step instructions. let’s follow the tutorial and implement it.

Step 1: Install Laravel Application

Let’s create a fresh new Laravel project. It’s optional if you have already created then you may go ahead.

Step 2: Install JetStream

In this step, we will install Jetstream using the composer command.  so let’s run this command.

Execute this command to generate authentication templates such as login, register, and email verification.

Now, let’s node js package.

Next, run the below command.

Step 3: Add Database Detail

Go to the .env file and configure your database details. Define the database name, user name, and password of your database.

now, we need to run the migration command to create a database table.

Step 3: Install Socialite

In this step install Socialite Package that provides API to connect with your Facebook account. So, run the below command.

Step 4: Create Facebook App

Now you have to create Facebook App from here to get the App Id and Secret key. To create Facebook App You can also follow our tutorial

Then you have to set the App Id, Secret key, and call back URL in the config file, so open config/services.php and set the app id and secret this way:

Then you have to add Facebook client id and client secret in the .env file:

Step 5: Add Column In Database

In this step, You have to create a migration for adding facebook_id in your user table. So let’s run this command:

Now go to the newly generated Migration file and add the facebook_id column value.

Go to the model file app/Models/User.php and Update model this way:

Step 6: Create Routes

In this step, we have to add the route for Facebook login. so let’s add the route in the routes/web.php file.

Step 7: Create a Controller

In This Step we need to create a new controller to add method of facebook auth that method will handle facebook callback url. So let’s run this command.

Now add code on your app/Http/Controllers/FacebookController.php file.

Step 8: Update Blade File

Now we need to add a blade file view so first, create a new file resources/views/auth/login.blade.php file and add below code:

Use the following URL to see how far you’ve progressed:

Result :

I hope you will like the Tutorial and it will help you to learn Laravel Socialite Login with Facebook. Please comment below if you have any questions.

You can also hire laravel developers to build your custom solutions on laravel. For exploring the available extensions for Bagisto, you can check out the bagisto extension marketplace.


. . .

Leave a Comment

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

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home