Login with Facebook In Laravel 7/6 Example

In this tutorial you will learn about the Login with Facebook In Laravel 7/6 Example and its application with practical example.

In this Login with facebook in Laravel 7/6 example tutorial I’ll show you how to integrate facebook login in laravel 7/6 using socialite package. Integrating Facebook login in Laravel 7/6 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.

Login with Facebook In Laravel 7/6 Example

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

  • Step 1: Install Laravel New App
  • Step 2: Connect App to Database
  • Step 3: Download Socialite Package
  • Step 4: Create Facebook App
  • Step 5: Create Auth Scaffolding
  • Step 6: Add Route
  • Step 7: Create Controller By Artisan Command
  • Step 8: Add Facebook Login Button On Blade View
  • Step 9: Run Development Server

Step 1: Install Laravel New App

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

Step 2: Connect App to Database

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.

Step 3: Download Socialite Package

In this step we will Install Socialite Package via Composer using following command:

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

config/app.php

Step 4: Create 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:

Now, go to User.php model and add fillable property like below:

Now, go to database/migrations directory and open create_users_table.php. Then put the following code into it:

Before you run PHP artisan migrate command. Navigate to app/providers/ directory and open AppServiceProvider.php. Then add the following code into it:

Now, in this step we will create model and migration file. Please run the following command:

Step 5: Create Auth Scaffolding

Install Laravel UI

Create Auth

NPM Install

Step 6: Add Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 7: Create Controller By Artisan Command

Now, lets create a controller named SocialController using command given below –

Now, go to app/http/controllers/ directory and open SocialController.php. Then put the following code into your SocialController.php file

Step 8: Add Facebook Login Button On Blade View

In this step, you need to add Facebook login button in blade views file. Now, go to resources/views/Auth directory and open login.blade.php. Then put Facebook social login button in login.blade.php file

Now, go to resources/views/Auth directory and open register.blade.php. Then add Facebook social login button in register.blade.php file:

Step 9: 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 Login with Facebook In Laravel 7/6 Example and its application with practical example. I hope you will like this tutorial.