Facebook Login Integration in Laravel 6
Dec 01, 2019In this article I'm going to walk you through Facebook Login integration via Laravel's Socialite package. This app is completely going to be
laravel new social
Now, secure the project by running valet secure
valet secure social
We'll use the laravel's inbuilt authentication system for our project. So run the following
composer require laravel/ui
laravel/ui
ships with three variants such as vue, react and basic bootstrap one. We'll use the basic bootstrap version.
php artisan ui bootstrap
Now we need to run the npm commands to set up the base
npm install && npm run dev
After running the npm modules, run the following comand to publish the authentication scaffolding
php artisan ui:auth
If everything goes fine until now, you'll be seeing laravel's default homepage as follows

Laravel Socialite
Lets require the laravel socialite package for our project
composer require laravel/socialite
Database
Instead of maintaining a different columns for multiple social accounts which you might need in the future, lets put all the social link information on the same column named "social" and we'll make it as
Please note that in the above code I have made the
We'll create the database named social and we'll provide the details on .env file.
Now, lets clear the cached config and migrate the tables
php artisan config:cache
php artisan migrate
Since we have made our social column as json, we have to define getters in our User
model so that we will get social result as object instead of string
Let's create SocialController inside Auth
folder
php artisan make:controller Auth/SocialController
Then, we'll make changes to our web.php
file to handle the facebook login
Here please note that I have used dynamic {provider} instead of static facebook. This is because, incase if you plan to add more social login options, then you need to write code again for that.
Facebook configuration
Head over to developers.facebook.com after logging in facebook and create your first app
Please select the

Select the

Enter our project's base url below

Now click on Basic option under the Settings in left sidebar and fill the following details
- Namespace - should be unique name
- App Domains - your project's base url

Finally, add the redirect url under the Facebook Login > Settings on the left sidebar

I prefer maintaining all the facebook social login details like .env
file rather than the configuration file directly.
Now, lets add the facebook configuration to app/config/services.php
file like the below
View
Finally, lets add the facebook login link mentioned above to the following pages.
- auth/login.blade.php
- auth/register.blade.php
Thats all you have to do to integrate Facebook login in Laravel 6. Hope you find this useful.
Happy Coding