Category Archives: Laravel

Laravel Tutorials

Laravel 7/6 Autocomplete Search using Jquery UI

In this Laravel 7/6 Autocomplete Search using Jquery UI tutorial I will show you how to create autocomplete input or search box using jquery ui in laravel. In this tutorial you will learn to create autocomplete input box using jquery ui in laravel.

In this example we will be using autocomplete jquery ui plugin. The jquery autocomplete plugin is used to create dynamic autocomplete input with several options. In this example you will learn how to implement jquery autocomplete in laravel.

Laravel 7/6 Autocomplete Search using Jquery UI

In this article, I will show you to create a dynamic database driven ajax jquery autocomplete in Laravel. You will also learn to create a dynamic search dropdown autocomplete which will fetch options from database table using jquery autocomplete.

  • Install Laravel App
  • Setup Database
  • Generate Fake Records
  • Make Routes
  • Create Controller & Methods
  • Create Blade View
  • Conclusion

1: Install Laravel App

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

2: Setup 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.

3: Generate Fake Records

In this step we will add some dummy data into database.

Use following command to add 100 fake records in database :

4: Make Routes

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

5: Create Controller

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

Now, go to app/controllers/AutoCompleteController.php and put the below code :

6: Create Blade view

In this step we will create a blade file. Go to app/resources/views and create one file name search.blade.php .

7: Start 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 –

Laravel 7/6 Cron Job Scheduling

In this Laravel 7/6 Cron Job Scheduling tutorial I will show you how to schedule or create cron job in laravel. In this tutorial you will learn to create or schedule cron job in laravel.

In this tutorial we will learn about laravel custom cron job scheduling, laravel run cron job manually, sey cron job in cpanel, laravel run cron job manually, laravel scheduler every second, how to run cron job in laravel.

Laravel 7/6 Cron Job Scheduling

  • Create Command Class
  • Implement Logic
  • Register Command
  • Test in Localhost
  • Laravel Set CronJob Live Server

Step 1: Create Command Class

Next, We need to create command class run by below command in command prompt :

Step 2: Implement Logic

After run this above command, it will create a new class name TodayUsers.php in app/Console/Commands/ folder. So go to app/Console/Commands/TodayUsers.php and implement your logic here :

Step 3: Register Command

After creating your logic in TodayUsers.php file. Now we need to register command in kernel.php file with task scheduling. Open app/Console/Kernel.php/ and schedule the task.

In Kernel.php file we will schedule the task to be done, when this command excute(run). In this example we will schedule the task excute for every minute.

Step 4: Test in Localhost

Step 5: Laravel Set CronJob on live server

In Laravel More Cronjob Schedule Options are available.
->cron(‘* * * * * *’); – Run the task on a custom Cron schedule

->everyMinute(); – Run the task every minute

->everyFiveMinutes(); – Run the task every five minutes

->hourly(); – Run the task every hour

->daily(); – Run the task every day at midnight

->dailyAt(’13:00′); – Run the task every day at midnight

->twiceDaily(1, 13); – Run the task daily at 1:00 & 13:00

->weekly(); – Run the task weekly

->monthly(); -Run the task every month

->monthlyOn(4, ’15:00′) – Run the task every month on the 4th at 15:00

->quarterly(); – Run the task every quarter

->yearly(); – Run the task every year

->timezone(‘America/New_York’); – Set the timezone Addiitional schedule constraints are listed below,

->weekdays(); – Limit the task to weekdays

->sundays(); – Limit the task to Sunday

->mondays(); – Limit the task to Monday

->tuesdays(); – Limit the task to Tuesday

->wednesdays(); – Limit the task to Wednesday

->thursdays(); – Limit the task to Thursday

->fridays(); – Limit the task to Friday

->saturdays(); – Limit the task to Saturday

Laravel 7/6 Email Verification Tutorial Example

In this Laravel 7/6 Email Verification Tutorial I will show you how to implement email verification for newly registered users in laravel. In this tutorial you will learn to enable email verification for account activation in laravel.

Laravel provides built-in email verification system for newly registered user. Using this, newly registered user will get an email with an account activation link. This activation link is used for account verification. When activation link is clicked, this will make user account verified and active for the application. Once user account is activated then it will be allowed to access protected routes; which can be accessible only by verified accounts.

Laravel 7/6 Email Verification Tutorial Example

In this step by step tutorial, we’ll show you how to setup email verification system for newly registered user in laravel.

  • Install Laravel Fresh Setup
  • Setup Database and SMTP Detail
  • Create Auth Scaffolding
  • Migrate Database
  • Add Route
  • Add Middleware In Controller
  • Run Development Server
  • Conclusion

1. Install Laravel Fresh Setup

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

2. Setup 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.

Now we will setup SMTP credential in .env to send emails. We are using mailtrap SMTP credential in this example.

3. Create Auth Scaffolding

Now we need to enable authentication scaffolding in laravel.

4. Migrate Database

Now, go to app/providers/AppServiceProvider.php and put the below code :

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

After migrating the database tables we need to add the MustVerifyEmail Contracts in App/User.php. Open the App/User.php file add the constructor like

5. 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

6. Add Middleware In Controller

We need to add Middleware in the controller constructor. Go to app/controllers/HomeController
and put this line $this->middleware([‘auth’, ‘verified’]); inside of constructor :

7. 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 –

Laravel 7/6 Send Email Tutorial Example

In this Laravel 7/6 Send Email Tutorial I will show you how to send email in laravel. In this tutorial you will learn how to send email in laravel using SMTP driver. Laravel comes with built-in api and driver support for SMTP, SendMail, Mailgun, Sendgrid, Mandrill, Amazon SES, SpartPost etc. In this article I will share example of sending an email in laravel application.

Laravel 7/6 Send Email Tutorial Example

In this step by step tutorial you will understand how to send emails in Laravel using SMTP driver.

  • Install Laravel Setup
  • Configuration SMTP in .env
  • Create Route & Blade View
  • Create Controller & Method
  • Run Development Server

1. Install Laravel Fresh Setup

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

2. Configuration SMTP in .env

In this step we will configure smtp settings in .env file as following:

3. Create Route & Blade View

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

Next, we will create email blade view file in view folder of view. Go to the resources/views/ and create a view file name email.blade.php. Put bellow code:

4. Create Controller & Method

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

Now open the controller let’s go to app/Http/Controllers/EmailController.php. Put the following code in it:

5. 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 –

Laravel 7/6 Ajax CRUD Example

In this Laravel 7/6 Ajax CRUD operation example tutorial I’ll show you how to create a simple ajax crud application in laravel 7/6. In this example we will learn how to create a simple ajax crud operation application in laravel 7/6. In this laravel 7/6 ajax crud application we will be using jQuery and ajax to delete data from datatable crud app and MySQL database in laravel 7/6 app.

In this tutorial, you will learn to implement ajax based CRUD (Create, Read, Update and Delete) operations in laravel.

Laravel 7/6 DataTable Ajax CRUD Example Tutorial

In this step by step guide, we will be creating a simple laravel 7/6 application to demonstrate you how to implement ajax based CRUD operations in laravel.

Laravel 7/6 Ajax CRUD Example

  • First Install New Laravel Setup
  • Configure .env file
  • Create One Model and Migration
  • Make Route
  • Generate(create) Controller
  • Create Blade View
  • Start Development Server
  • Conclusion

1). First Install New Laravel Setup

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

2). Configure .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.

Next go to app/datatabase/migrations and open users migration file and put the below code here

Now, go to app/providers/AppServiceProvider.php and put the below code :

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

3). Make 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

4). Generate (Create) Controller

In this step we will create a resource controller named AjaxController for crud operations using following command:

Next open your controller and replace crud methods as following:

5). Create blade view :

In this step, we will create one blade file name ajax-crud.blade.php.

Next step, we will create one modal. After create a modal it put closing of last div tag :


Next we will implement the ajax crud logic inside the script. Open your ajax-crud blade view file and put the below code after closing of body tag

6). 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 –

Laravel 7/6 Generate PDF Example

In this Laravel 7/6 Generate PDF Example tutorial, I will show you how to generate pdf from html blade view file in laravel. In this tutorial you will learn to generate, convert and download pdf file from html blade view file in laravel. While working with web application we come to situations where we need to generate or download pdf file for various purpose such as generate invoices, acknowledgment or tickets printing etc. In this tutorial we will be using laravel dom-pdf package to generate/create and download pdf.

Laravel 7/6 Generate PDF Example

In this step by step guide I will demonstrate you how to create or download pdf from laravel html blade view file in the laravel 7/6 Application.

  1. Install Laravel App
  2. Setup Database
  3. Install laravel-dompdf Package
  4. Make PDF Route
  5. Create GeneratePDF Controller
  6. Create Blade view for Generate Pdf
  7. Start Development Server

1. Install Laravel App

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

2. Setup 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.

3. Install laravel-dompdf Package

In this step, we will install laravel-dompdf Package via the composer dependency manager. Use the following command to install laravel-dompdf Package.

After successfully installing laravel dompdf package, we need to add service provider and alias in config/app.php file as following.

4. Make PDF 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

5. Create GeneratePDF Controller

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

After creating controller go to app/controllers/GeneratePdfController.php and put the following code in it:

 

6. Create Blade view for Generate Pdf

Now, we need to create blade view file. Go to app/resources/views and create one file name pdf_form.blade.php :

Now we create a one more blade view file name pdf_download.blade.php. Go to app/resources/views create file. This blade view file will download as pdf file. so put the below code here

7. 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 –

Laravel 7/6 Simple CRUD Application Example Tutorial

In this Laravel 7/6 Simple CRUD Application Example Tutorial I’ll show you how to create a simple crud application in laravel 7/6. In this example we will learn how to create a simple crud operation application in laravel 7/6. In this laravel 7/6 crud application we will be using jQuery and ajax to delete data from datatable crud app and MySQL database in laravel 7/6 app. In this article, you will learn how to create fully functional CRUD (Create, Read, Update and Delete) Application In laravel.

Laravel 7/6 Simple CRUD Application Example Tutorial

  • Step 1: Install Laravel New Setup
  • Step 2: Setup Database Credentials
  • Step 3: Generate Model and Migration
  • Step 4: Add Routes for CRUD Operation
  • Step 5: Create Resource CRUD Controller
  • Step 6: Create the blade view
  • Step 7: Start Development Server

Step 1: Install Laravel New Setup

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

Step 2: Setup Database Credentials

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: Generate Model and Migration

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

The above command will create one model name Product and also create one migration file for Product table. Now, go to database/migrations file and put the below here :

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

If you found any query builder error in command prompt go to  => app\Providers\AppServiceProvider.php and put the below code here :

And then run this below command :

Now, add the fillable property inside Product.php file.

Step 4: Add Routes For CRUD Operation

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 5: Create Resource CRUD Controller

In this step we will create a resource controller using following artisan command:

The above command will create a contoller name ProductController and also inside by default seven methods like index, store, create, update, destroy, show, edit.

Next open controller, Go to app/HTTP/Controller/ProductController and update the below code into your controller file:

Step 6: Create the blade view

Create the product folder. After successfully create product folder , we will create following blade files for CRUD (Create, Retrieve, Update, Delete) operations.

  1. Layout.blade.php
  2. List.blade.php
  3. Create.blade.php
  4. Edit.blade.php
Layout.blade.php

List.blade.php

Create.blade.php

Edit.blade.php

Step 7: 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 –

Laravel 7/6 DataTable Ajax CRUD Example Tutorial

In this Laravel 7/6 Datatables CRUD operation example tutorial I’ll show you how to create a simple crud application using yajra Datatables in laravel 7/6. In this example we will learn how to create a simple crud operation application using Datatables in laravel 7/6. In this laravel 7/6 crud application we will be using jQuery and ajax to delete data from datatable crud app and MySQL database in laravel 7/6 app.

In this tutorial, you will learn to implement ajax based CRUD (Create, Read, Update and Delete) operations using datatable js. In this tutorial, we will be using yajra datatable package for listing of records with pagination, sorting and filter (search) feature.

Laravel 7/6 DataTable Ajax CRUD Example Tutorial

In this step by step guide, we will be creating a simple laravel 7/6 application to demonstrate you how to install yajra datatable package and implement ajax based CRUD operations with datatable js.

  • Step 1: Install Fresh laravel Setup
  • Step 2: Set database Credentials
  • Step 3: Create Migration And Model
  • Step 4: Install Yajra DataTables in App
  • Step 5: Create Route, Controller & Blade View
  • Step 6: Run Development Server
  • Step 7: Live Demo

Step 1: Install Fresh Laravel Setup

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

Step 2: Set database Credentials

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: Create Migration And Model

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

Now go to database/migrations/ and open create_products_table.php file. Then put the following code into this file:

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

The above command will create tables in your database. Now, go to App directory and open Product.php file and then update the following code to into Product.php file as follow

app\Product.php

Step 4: Install Yajra Datatables Package in Laravel

In this step, we will install Yajra Datatables Package via the composer dependency manager. Use the following command to install Yajra Datatables Package.

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

config/app.php

After set providers and aliases then publish vendor run by following command.

Step 5: Create (Controller, Route, Blade)

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

2: Create Controller

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

Now, open app/Http/Controllers/ProductController.php and create some methods to add products, edit product and delete the product. In Product Controller, we need to create some methods:

  • Index()
  • Store()
  • Edit()
  • Destroy()

Index() method

Store() Method

Edit() Method

Delete() Method

Now, update all methods into your ProductController.php file as follow:

3: Create Blade View

Create a Button view

Now, we will create action.blade.php file. This file contains a two-button name edit and delete. So you can update the below code in your action button file.

Next, create a list.blade.php file in resources/views/ folder and update the below code in your product list file.

Script Code

Step 6: 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 –

Laravel 7/6 Paytm Payment Gateway Integration

In this Laravel 7/6 Paytm Payment Gateway Integration Example tutorial, I’ll show you how to integrate Paytm payment gateway in laravel 7/6. In this tutorial you will learn to integrate Paytm in laravel 7/6. In this step by step tutorial I’ll share laravel 7/6 Paytm integration example.

Paytm Payment Gateway

Paytm is one of the popular payment gateway, that allows us to accept payment from your customer. Paytm is very simple, hassle free and easy to integrate payment gateway. Integrating Paytm payment gateway in laravel 7/6 is a breeze.

Laravel 7/6 Paytm Payment Gateway Integration

In this tutorial, you will learn to integrate Paytm payment gateway in your laravel 7/6 project. Follow this step by step tutorial to learn Paytm payment gateway integration in laravel 7/6.

  • Install laravel fresh Setup
  • Configuration .env file
  • Install Anandsiddharth paytm package
  • Generate Migration and Create Model
  • Make Route
  • Create Controller
  • Create Blade View file
  • Start Development Server
  • Conclusion

Install laravel Fresh Project

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

Configuration in .env

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.

Install Anandsiddharth paytm package

Now, we need to install Anandsiddharth paytm package in our project. Open your terminal and switch to project directory and use the following composer command to install Anandsiddharth paytm package.

After installing the package, we need to register the provider and alias. Go to the app/config/app.php and put the below lines here :

Now we need to set a paytm credential as following. Go to the app/config/services.php and set the paytm credential

Generate Migration and Create Model

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

The above command will create a model name Event and also create a migration file for the events table. After that go to database/migrations file and put the below here :

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

Now, add the fillable property inside the Event.php file.

Make 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

Create Controller

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

Go to app/HTTP/Controller/EventController and put the below code :

Create Blade View file

Now, we need to create blade views file, Go to app/resources/views/ and create one file name event.blade.php :

Start 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 –

http://localhost:8000/event

Testing Card Credential

Laravel 7/6 Generate Fake Data Using Faker Example

In this Laravel 7/6 Generate Fake Data Using Faker Example tutorial, I will show you how to generate fake data using laravel faker. In this tutorial you will learn to generate fake or dummy data in a database table using faker in laravel project. While working with any web application using laravel we come situations where we need some dummy or test data to available in database. Laravel faker makes this job much easier using laravel faker we can generate fake data into the database table.

Laravel 7/6 Generate Fake Data Using Faker Example

In this tutorial, you will learn how to generate fake data into the database tables using laravel faker. Please follow the instruction give below:

  • Step 1: Download Fresh Laravel Setup
  • Step 2: Setup Database Credential
  • Step 3: Run Migration Command
  • Step 4: Create a Model & Migration File
  • Step 5: Create New Factory File
  • Step 6: Generate Fake Data Using Tinker
  • Step 7: Generate Fake Data Using Seeder

Step 1: Download Fresh Laravel Setup

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

Step 2: Setup Database Credential

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: Run Migration Command

In this step we will run following command to migrate database schema.

Step 4: Create a Model & Migration File

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

Let’s go to the app/Notes.php and put the below code in your files.

Next, go to database/migrations/2019_02_19_012129_create_notes_table.php and replace the below code into your file.

Step 5: Create New Factory File

In this step, we will create a factory file. Go to app/database/factories and inside this folder, we need to create a new file name NoteFactory.php and put the below code into your file.

Step 6: Generate Fake Data Using Tinker

Please use the following command to generate fake data using tinker:

Now, run following command to generate 100 rows of random Notes.

Step 7: Generate Fake Data Using Seeder

Let’s create seeder for Note using below artisan command.

The above command will generate NoteTableSeeder.php file in the database/seeds directory. Open NoteTableSeeder.php and update code shown as below.

Next step, we will declare NoteTableSeeder inside the DatabaseSeeder. The file is DatabaseSeeder located app/database/seeds.

DatabaseSeeder.php

Now, run the following command to generate 100 fake rows in the Note table.

Please check the database now for test data.

Laravel 7/6 Socialite Google Login Example

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

Laravel 7/6 Socialite Google Login Example

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

  • Install laravel App
  • Add Database Details
  • Install Socialite Package For Google Login
  • Create Google App
  • Set Google App Details
  • Add Routes
  • Generate Auth Files By Artisan
  • Create Controller
  • Add Socialite Google Login Button In Blade Views
  • Run Development Server

Step1: Install laravel App

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

Step 2: Add Database Details

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: Install Socialite Package For Google Login

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

Now, Navigate to config directory and open app.php file. Then add aliese and provider app.php:

Step 4: Create Google App

Step 1:-
Visit Google Developer Console. And create a new project
Step 2:-
Please fill up the required information.
Step 3:-
After creating new project you need to select the created projects on the top menu. Then click on OAuth consent screen and select the given option according to your requirement:
Step 4:-
Next, you need to provide your website URL, privacy policy URL, etc.
Step 5:-
Click on left side menu credentials then select OAuth client ID.
Step 6:-
After that, the below form will be apper. Please select Web application from application type options. Once you have select Web application option, then one form will appear on web page. Here you have to define Name and you have also define Authorized redirect URIs field and lastly click on Create button.
Step 7:-
Once you have click on the create button, then you can get your Client ID and your client secret key.

Step 5: Add Google App Details

Now, we need to add google app details with redirect url. So, go to the config directory and open service.php file. And add the google client id, secret and redirect url in service.php file:

After that, open User.php model and add the following properties into User.php model file:

Now, go to app/database folder and open create_users_table.php. And add the following code into your create_users_table.php file:

Before you run PHP artisan migrate command, Navigate to go to app/providers folder and open AppServiceProvider.php file. And add the following code into your AppServiceProvider.php file:

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

Step 6: Generate Auth File By Artisan

Install Laravel UI

Create Auth

NPM Install

Step 7: Add Routes

Now, you need to add routes in the web.php file. So navigate to routes folder and open web.php file. Then add the following routes into web.php file:

Step 8: Create Controller

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

Then go to app/controllers folder and open GoogleLoginController.php. And put the following code into your GoogleLoginController.php file:

Step 9: Add Socialite Google Login Button In Blade Views

Go to Resources/Views/Auth folder and open register.blade.php. Then add a laravel socialite google login button in register.blade.php file:

Next, go to Resources/Views/Auth folder and open login.blade.php. Then add a laravel socialite google login button in login.blade.php file:

Step 10: 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 –

Login with Facebook In Laravel 7/6 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 –