Laravel6 - How to implement yajra datatable using yajra/laravel-datatables-oracle

In this article, we will share with you how to implement yajra datatable in laravel application using yajra/laravel-datatables-oracle package. this package is providing easy to used datatable functionality and implement in your laravel application.

Yajra datatable provides us many useful features like searching, ordering, sorting, pagination, etc.. The stated goal of DataTables is "To enhance the accessibility of data in HTML tables". In order to achieve this we recognize that DataTables has two categories of users that interact with the interfaces the software has:

If you never used befor yajra datatable in your laravel application then don't worry just follow the step and easy to implement. after done all the step then you can see the following preview.


Step - 1 Install package

First, we need to install yajra/laravel-datatables-oracle package using run following command in your terminal. we need "yajra/laravel-datatables-oracle": "^6.0.*" version for laravel 6.

composer require "yajra/laravel-datatables-oracle": "^6.0.*"

Step - 2 Set the Service Provider and Facade alias

After installing the package, open your Laravel config file located at config/app.php and add the following lines.

In the $providers array add the following service provider for this package.

'providers' => [
    // ...

After completing the step above, use the following command to publish configuration & assets:

php artisan vendor:publish --tag=datatables

After running this command in your terminal then config/datatables.php file automatic created. you can change the default setting in this file.

Step - 3 Create route

After installing package and configure all the set up then next things is make following two route in routes/web.php file.

// Route resorce for users listing.
Route::resource('users', 'UserController');
// Route for get users for yajra post request.
Route::get('get-users', 'UserController@getUsers')->name('get-users');

Step - 4 Create controller

After, done above two routes then we need to create UserController.php file help of following artisan command.

php artisan make:controller UserController

After running this command your UserController.php file automatic created on app/Http/Controllers a folder. just open it and write the following code into that file.


namespace App\Http\Controllers;

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

class UserController extends Controller
    public function index()
    	return view('users-index');

    public function getUsers(Request $request)
    	$data = User::all();
        return \DataTables::of($data)
            ->addColumn('Actions', function($data) {
                return '<a href='.\URL::route('users.edit', $data->id).' class="btn btn-success btn-sm">Edit</a>
                    <a href='.\URL::route('', $data->id).' class="btn btn-info btn-sm">View</a>';
            ->addColumn('Status', function($data) {
                if($data->is_active == '1'){
                    return '<label class="badge badge-success">Active</label>';
                    return '<label class="badge badge-danger">Inactive</label>';

Step - 5 Change in app layout file

Now we make some changes in your default layouts/app.blade.php file. make the following change in your file. just remove default app.js file and add jQuery CDN there and also ass two new section @yield('style') and @yield('script')

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('', 'Laravel') }}</title>

    <!-- Scripts -->
    <script type="text/javascript" src=""></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//">
    <link href="" rel="stylesheet">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
    <div id="app">
        <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
            <div class="container">
                <a class="navbar-brand" href="{{ url('/') }}">
                    HackTheStuff Demos
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
                    <span class="navbar-toggler-icon"></span>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <!-- Left Side Of Navbar -->
                    <ul class="navbar-nav mr-auto">


                    <!-- Right Side Of Navbar -->
                    <ul class="navbar-nav ml-auto">
                        <!-- Authentication Links -->
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
                            @if (Route::has('register'))
                                <li class="nav-item">
                                    <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
                            <li class="nav-item dropdown">
                                <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                    {{ Auth::user()->name }} <span class="caret"></span>

                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                    <a class="dropdown-item" href="{{ route('logout') }}"
                                        {{ __('Logout') }}

                                    <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">

        <main class="py-4">

Step - 6 Create blade file

After done controller file then we create one laravel blade HTML file that listing users' data. Now we are creating one simple blade file in resources/views/users-index.blade.php file and here we are making a very simple HTML layout for users listing.


<link rel="stylesheet" type="text/css" href="">

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">{{ __('Users Listing') }}</div>

                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered datatable">
                                    <th>First Name</th>
                                    <th>Last Name</th>
                                    <th width="150" class="text-center">Action</th>

<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
    $(document).ready(function() {
            processing: true,
            serverSide: true,
            autoWidth: false,
            pageLength: 5,
            // scrollX: true,
            "order": [[ 0, "desc" ]],
            ajax: '{{ route('get-users') }}',
            columns: [
                {data: 'id', name: 'id'},
                {data: 'first_name', name: 'first_name'},
                {data: 'last_name', name: 'last_name'},
                {data: 'email', name: 'email'},
                {data: 'Status', name: 'Status'},
                {data: 'Actions', name: 'Actions',orderable:false,serachable:false,sClass:'text-center'},


As you can see, yajra datatable is very easy to use in laravel application help of yajra/laravel-datatables-oracle package.

We hope these tutorials help everyone. if you have any issues or questions regarding yajra daatatable implementation so please comment below. Thanks..