How to Use Yajra Datatables in Laravel 8

In this tutorial you will learn about the How to Use Yajra Datatables in Laravel 8 and its application with practical example.

In this How to Use Yajra Datatables in Laravel 8 tutorial, I’ll show you how to install and use yajra DataTables in your laravel 8 application with example. In this tutorial you will learn to install and use yajra DataTables in your laravel 8 application. In this example, we will be using yajra datatable package for listing of records with pagination, sorting and filter (search) feature. Laravel Yajra datatables package comes with many built-in features for searching and sorting functionality.

How to Use Yajra Datatables in Laravel 8

In this step by step tutorial I’ll guide you through the process to install and use yajra DataTables in your laravel application. In this tutorial I will demonstrate you with example installation and use of DataTables in laravel. Please follow the instruction given below:

  1. Install Laravel App
  2. Install Yajra Datatables
  3. Set Up Model and Migrations
  4. Insert Dummy Data
  5. Create Controller
  6. Define Route
  7. Create View

Install Laravel App

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

Switch into the project project directory using following command

Install Yajra Datatable Package

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

Run vendor publish command further this step is optional:

Set Up Model and Migrations

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

Open database/migrations/timestamp_create_students_table.php file and add the given below code.

Next, go to app/Models/Student.php file and add the $fillable property in the Student model as following.

Now, run the migration to create database table using following artisan command:

Insert Dummy Data or Records

Open the database/seeds/DatabaseSeeder.php file and add the following code.

Run the following command to generate dummy data:

Create DataTable Controller

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

Open app/Http/Controllers/StudentController.php file and add the following code.

Define 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

Display Data with Yajra Datatables

Open resources/views/welcome.blade.php file and put the following code.

resources/views/welcome.blade.php

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 How to Use Yajra Datatables in Laravel 8 and its application with practical example. I hope you will like this tutorial.