Laravel 8 Login with Facebook Account Example

In this tutorial you will learn about the Laravel 8 Login with Facebook Account Example and its application with practical example.

In this Login with facebook in Laravel 8 example tutorial I’ll show you how to integrate facebook login in laravel 8 using socialite package. Integrating Facebook login in Laravel 8 using socialite package is much easier. Allowing users to login with their social media accounts makes registration/login process much easier, it also encourages more users to register for your application.

Laravel 8 Login with Facebook Account Example

In this step by step tutorial, you will learn to integrate Facebook login with your laravel 8 application. Please follow the steps give below:

  • Install Laravel 8 App
  • Configure Database With App
  • Configure Facebook App
  • Install Socialite & Configure
  • Add Field In Table Using Migration
  • Install Jetstream Auth
  • Build Routes
  • Create Facebook Login Controller By Command
  • Integrate FB Login Button In Login Page
  • Start Development Server

Install Laravel 8

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Configure Database In .env file

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

.env

Configure Facebook App

Step 1:-

Go to Facebook’s developers site https://developers.facebook.com/ and log in with your Facebook account. There in Facebook developers Dashboard you have option to Create App. Lets create a Facebook Login App simply providing App Name and Contact Email.

Step 2:-

After creating the facebook app, go to setting->advanced and set redirect url

Step 3:-

Then, go to Facebook Login -> Settings and scroll down to “Valid OAuth Redirect URL” and set your callback URL

Step 4:-

After creating app, go to Settings -> Basic and get your newly created App ID and App Secret.

Now, go to config directory and open service.php file and add the client id, secret and callback url:

Install Socialite Package via Composer

After Installing ‘socialite’ package, we need to add service provider and alias in config/app.php file as following.

config/app.php

Add Field In Table Using Migration

Now, use the following command to create a migration file to add a column in database table:

Once this command is executed you will find a migration file created under “database/migrations”. lets open migration file and put following code in it –

After successfully add field in database table. Then add fillable property in User.php model, which is found inside app/Models/ directory:

Now, run following command to migrate database schema.

Install Jetstream Auth

In this step, install jetstream laravel auth scaffolding package with livewire. We have provided a complete guide in this Laravel 8 Auth Scaffolding using Jetstream Tutorial.

Build Routes

After this, we need to add following routes in “routes/web.php” file along with a resource route. Lets open “routes/web.php” file and add following route.

routes/web.php

Create Facebook Login Controller

Now, lets create a controller for facebook login. Create a controller named FacebookSocialiteController using command given below –

Once the above command executed, it will create a controller file FacebookSocialiteController.php in app/Http/Controllers/ directory. Open the FacebookSocialiteController.php file and put the following code in it.

app/Http/Controllers/FacebookSocialiteController.php

Integrate FB Login Button In Login Page

Now, we will add facebook login button into login.blade.php file. So, open login.blade.php, which is found inside resources/views/auth/ directory:

Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Laravel 8 Login with Facebook Account Example and its application with practical example. I hope you will like this tutorial.