How to Install Yajra DataTables With Laravel 6 Application e.g.

In this laravel 6 yajra datatables tutorial, We’ll show you how to install Yajra DataTables in laravel with example.
And this example also works with laravel 5.8.

DataTables is a plug-in for the jQuery Javascript library. Laravel Yajra DataTables Package provides many functionalities like searching, sorting, pagination on the table.


  • Install Laravel
  • Configuration .evn file
  • Run Migration
  • Install Yajra DataTables
  • Add Fake Data
  • Create Route, Controller & Blade View
  • Start Development Server
  • Conclusion

1. Install Laravel

First We need to Download fresh latest Laravel setup. Use the below command to download the laravel fresh setup on your system.

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

2. Configuration .env file

In this step, we will set database credential in .env file

laravel datatables

3. Run Migration

We need to do the migration of tables using below command:

php artisan migrate

This command will create tables in our database.

4. Install Yajra Datatable Package in Laravel

Now We will Install Yajra Datatable Packages in your laravel 6 setups. Use the below command and install yajra packages in your laravel application.

composer require yajra/laravel-datatables-oracle

After successfully Install Yajra Datatable Packages, open config/app.php file and add service provider and alias.


'providers' => [


'aliases' => [

'Datatables' => Yajra\Datatables\Facades\Datatables::class,

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

php artisan vendor:publish

5. Add Fake Records

We need to add some records in the database. Use the below command for adding fake records in your database.

php artisan tinker

After running the php artisan tinker. Use the below command. This command will add 150 fake records in your database

>>> factory(App\User::class, 150)->create();

6. Create Route, Controller & Blade View

Add Route

Now we will add routes in web.php file as like below.

Open routes/web.php file

Route::get('users', '[email protected]');

Route::get('users-list', '[email protected]');

Create Controller

We need to create a new controller UsersController that will manage two methods. lets use this below command and create a Controller.

php artisan make:controller UsersController

Now open the controller let’s go to the => app/Http/Controllers/UsersController.php. Put the below Code


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Redirect,Response,DB,Config;
use Datatables;
class UsersController extends Controller
    public function index()
        return view('users');
    public function usersList()
        $users = DB::table('users')->select('*');
        return datatables()->of($users)

Create Blade View

Next, create users.blade.php file in resources/views/ folder and copy paste the following code.

<!DOCTYPE html>

<html lang="en">
<title>Laravel DataTable - Tuts Make</title>
<link href="" rel="stylesheet">  
<link  href="" rel="stylesheet">
<script src=""></script>  
<script src=""></script>
<script src=""></script>
         <div class="container">
               <h2>Laravel DataTable - Tuts Make</h2>
            <table class="table table-bordered" id="laravel_datatable">
                     <th>Created at</th>
   $(document).ready( function () {
           processing: true,
           serverSide: true,
           ajax: "{{ url('users-list') }}",
           columns: [
                    { data: 'id', name: 'id' },
                    { data: 'name', name: 'name' },
                    { data: 'email', name: 'email' },
                    { data: 'created_at', name: 'created_at' }

7. Start Development Server

In this step, we will use the php artisan serve command. It will start your server locally

php artisan serve

If you want to run the project diffrent port so use this below command

php artisan serve --port=8080

Now we are ready to run our example so run bellow command to quick run.


If you are not run php artisan server command, direct go to your browser and type the URL


Laravel DataTables
Laravel DataTables

8. Conclusion

In this article, We have successfully installed & use yajra datatables in the laravel 6 Application. our examples run quickly.

If you have any questions or thoughts to share, use the comment form below to reach us.


  1. booties said:

    I read this paragraph completely on the topic of
    the difference of most up-to-date and previous technologies, it’s
    amazing article.

    September 6, 2019
  2. Zaheer Ahmed said:

    While trying to install data tables on Laravel 6.0.4 I get this error and installation aborted :
    – Conclusion: remove laravel/framework v6.0.4
    – Conclusion: don’t install laravel/framework v6.0.4
    – laravel/passport 6.0.x-dev requires illuminate/http ~5.6 ->
    Long error.

    October 1, 2019
  3. sirgliofrei said:

    I have read a few excellent stuff here. Definitely worth bookmarking for revisiting. I surprise how much attempt you put to make this type of fantastic informative site.

    October 9, 2019
  4. ERIC KWAKYE said:

    Hi Senior..
    Your aryicle is one of the best.
    If you can do one with datatables with export features and crud all in one.
    it will be appreciated. i tried the one datatables as a service with crud but whole lot of issues.

    November 12, 2019
  5. Hameed Hussain said:

    I have created same but I have created the controller and view inside one folder

    like http/controller/admin/UserController
    like resource/view/admin/customer/user.blade.php

    When I open the page it is blank.

    Can you please help me to fix

    November 29, 2019
  6. Las Noches said:

    Thank you sharing this content,
    I’ve followed your steps and got great results!

    December 18, 2019

Leave a Reply

Your email address will not be published. Required fields are marked *