Laravel 8 Yajra Datatable Example Tutorial

Laravel 8 Yajra Datatable Example Tutorial

In this tutorial, we have learn how to Laravel 8 Yajra Datatable Example Tutorial and i will share with you how to install and use yajra datatables laravel 8 in application. we will use datatables laravel datatables plugin. we will write step be step tutorial for laravel 8 datatables ajax.

Datatables provides us quick search, pagination, ordering, sorting and etc. Datatables is basically jQuery plugins that allows you to add advanced interaction controls to your HTML tables data. Datatables also provide ajax for data searching and getting. you can give very quick layout for search and sorting using Datatables.

You have to just follow few step for implement yajra datatables laravel example. In this example i give you example from scratch. So just follow bellow step, you will find preview and also demo for check how it is working.

Laravel 8 Yajra Datatable Example

Laravel 8 Yajra Datatable Example Tutorial

Step 1: Install Laravel 5.8

Read Also :  Laravel 8 cURL HTTP Request Example

In this step, if you haven’t laravel 8 application setup then we have to get fresh laravel 8 application. So run bellow command and get clean fresh laravel 8 application.

composer create-project --prefer-dist laravel/laravel blog

Step 2 : Install Yajra Datatable Package

We need to install yajra datatable composer package for datatable, so you can install using following command:

composer require yajra/laravel-datatables-oracle

After that you need to set providers and alias.



'providers' => [

'aliases' => [
'DataTables' => Yajra\DataTables\Facades\DataTables::class,


Step 3: Create Dummy Records

In this step, we will create some dummy users using tinker factory. so let’s create dummy records using bellow command:

php artisan tinker
factory(App\User::class, 200)->create();

Step 4: Create Route

In this is step we need to create route for datatables layout file and another one for getting data. so open your routes/web.php file and add following route.

Read Also :  How to Send Bulk Mail in Laravel 8 Using Queue


Route::get('users', [UserController::class, "index"])->name("users");

Step 5: Create Controller

In this point, now we should create new controller as UserController. this controller will manage layout and getting data request and return response, so put bellow content in controller file:



  namespace App\Http\Controllers;

  use App\User;
  use Illuminate\Http\Request;
  use DataTables;

  class UserController extends Controller
    * Display a listing of the resource.
    * @return \Illuminate\Http\Response
  public function index(Request $request)
   if ($request->ajax()) {
   $data = User::latest()->get();
   return Datatables::of($data)
   ->addColumn('action', function($row){

   $btn = '<a href="javascript:void(0)" class="edit btn btn-primary btn-sm">View</a>';

   return $btn;

return view('users');

Step 6: Create View

In Last step, let’s create users.blade.php(resources/views/users.blade.php) for layout and we will write design code here and put following code:


<!DOCTYPE html>
  <title>Laravel 8 Datatables Tutorial -</title>
  <meta name="csrf-token" content="{{ csrf_token() }}">
  <link rel="stylesheet" href="" />
  <link href="" rel="stylesheet">
  <link href="" rel="stylesheet">
  <script src=""></script> 
  <script src=""></script>
  <script src=""></script>
  <script src=""></script>
  <script src=""></script>

 <div class="container">
  <h1>Laravel 8 Datatables Tutorial <br/></h1>
  <table class="table table-bordered data-table">
     <th width="100px">Action</th>


<script type="text/javascript">
 $(function () {

  var table = $('.data-table').DataTable({
   processing: true,
   serverSide: true,
   ajax: "{{ route('users') }}",
   columns: [
     {data: 'DT_RowIndex', name: 'DT_RowIndex'},
     {data: 'name', name: 'name'},
     {data: 'email', name: 'email'},
     {data: 'action', name: 'action', orderable: false, searchable: false},


I hope you understand of Laravel 8 Yajra Datatable it can help you…

Read Also :  Laravel Blade For Loop Example