Laravel 8 YajraBox Server Side Datatable Tutorial

Reading Time: 6 minutes

Inside this article we will see the concept of Laravel 8 yajrabox server side datatable tutorial. Yajrabox is nothing, it’s package by the help of which we will integrate server side datatable.

We will implement Ajax DataTable in Laravel i.e Yajrabox DataTable. Datatables provides searching, pagination, ordering, sorting and etc. You need to follow the given steps to implement server side datatable Yajrabox in Laravel.

Learn More –

Let’s get started.

Laravel Installation

We will create laravel project using composer. So, please make sure your system should have composer installed. If not, may be this article will help you to Install composer in system.

Here is the command to create a laravel project-

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

To start the development server of Laravel –

php artisan serve


Assuming laravel already installed inside your system.

Database also configured with application.

Install Yajra Datatable

To install yajrabox, we need to run a composer command. Open up the terminal and type this command and execute.

$ composer require yajra/laravel-datatables-oracle

While installation of this package, you will get such type of screen over terminal.

Update Application Provider List

After installation yajra package via composer.

We need to go into laravel application and open /config/app.php.

Add this code to providers & aliases array.

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

Migration & Dump Test Data

To migrate default migrations of application to database, we need to run this command.

$ php artisan migrate

It will run all pending migrations.

Next, we need test data. We have two options to add fake data to users table.

  • By using Tinker Shell to Run
  • By using DatabaseSeeder.php file

Artisan Tinker Shell

Using DatabaseSeeder.php


namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
     * Seed the application's database.
     * @return void
    public function run()

To run this seeder, back to terminal and type the command as –

$ php artisan db:seed

Create Route

Open web.php from /routes folder. Open up the file web.php and add this route code.


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


Create Controller

Next, we need UserController. To create this controller, we have to run artisan command. Controllers will be stored inside /app/Http/Controllers folder.

$ php artisan make:controller UserController

Open up the file UserController.php and write this complete code into it.

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
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::select('*');
            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');

Create Blade Layout File

To create blade layout file, go to /resources/views folder. Create a file users.blade.php. Open up the file and write this complete code into it.

<!DOCTYPE html>

    <title>Laravel 8 YajraBox Datatable Tutorial - Online Web Tutor</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" style="margin-top: 50px;">
        <h4 style="text-align: center;">Laravel 8 YajraBox Datatable Tutorial - Online Web Tutor</h4>
        <table class="table table-bordered" id="data-table">
                    <th width="100px">Action</th>


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

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



Application Testing

Run this command into project terminal to start development server,

php artisan serve


We hope this article helped you to learn about Laravel 8 YajraBox Server Side Datatable Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more