Use Server Side Datatable Laravel 5.8

In this post, we are going to know about Server Side Datatable using Laravel 5.8. Data Table is one of the most important plugins in jQuery Library to show data in tables with the advance search function.

Use Server Side Datatable Laravel 5.8

Datatables is very important for showing large data into the table. the main advantage of the data table is it gives to users the advanced search function to filter data and It also provides a lot of user-friendly functionalities like sort, pagination, and searches, and others functions to handle the database data in our web pages.

We will use using yajra/laravel-datatables-oracle package in this blog post this package help us to load web page faster than normal HTML table.

Step 1: Install Laravel

First, we need to install Laravel application to install the latest application use the flowing command.

laravel new dataTables

Step 2: Install Composer Package

In this step, we will install laravel yajra/laravel-datatables-oracle package for use to generate Server Side Datatable. So we need to just run following command to this install package.

composer require yajra/laravel-datatables-oracle:"~9.0"

Step 3: Register provider 

Register provider and facade on your config/app.php file.

'providers' => [

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

Step 4: Create a New Model, Controller, and Migration

Here, we want to create a new modal, controller and migration for Products table so first fire bellow command.

php artisan make:model Product -mc

Above command, will create Model, Controller, and Migration for Product. In the migration table file, we need to add some number of columns details for product table like name, description, and price etc.


use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('products', function (Blueprint $table) {

     * Reverse the migrations.
     * @return void
    public function down()

After That don’t forget to connect with a database in .env and restart the server than that run the flowing command to migrate the table product table.

php artisan migrate

Step 5: Update Product Modal

Then we need to update the Product model file in our application like fillable, primary key, product, etc. 


namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
    protected $fillable = [
        'name', 'description', 'price',

Step 6 Add Some Routes

Add the first route to show data table and the second route to fetch data from the data table. here we use get method for both routes

Route::get('products-datatable', 'ProductController@datatable')->name('product.datatable');
Route::get('products-data', 'ProductController@productsList')->name('');

Step 6: Update Controller with Some Methods

Here we use two methods one for view page and another one fetch data from the database.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Product;
use DataTables;
class ProductController extends Controller
    public function datatable(){
        return view('products.datatable');

    public function productsList(){
        return DataTables::of(Product::query())->make(true);


Step 7: Add a Blade File

At the final step, we make a one blade file in the products folder. we use some JS library CDN link and some simple javascript code.

<!DOCTYPE html>
<html lang="en">
  <meta charset=UTF-8>
  <meta name=viewport content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link href="//" rel="stylesheet">
  <link rel="stylesheet" href="//">

  <script src=//></script>
  <script src=//></script>

<div >

  <div >

   <div >Server Side Datatable in Laravel 5</div>

   <div >

     <table id="product-table">





$(function() {
    processing: true,
    serverSide: true,
    ajax: '{!! route('') !!}',
    columns: [
      { data: 'id', name: 'id' },
      { data: 'name', name: 'name' },
      { data: 'description', name: 'description' },
      { data: 'price', name: 'price' }


So here we completed post on Use Server Side Datatable Laravel 5.8.

Good Luck!