Server side Laravel DataTables example

Today, We want to share with you Server side Laravel DataTables example.In this post we will show you DataTables Server-side Processing with Laravel 5.8, hear for Laravel 5.8 – DataTables Server-side Processing we will give you demo and example for implement.In this post, we will learn about Laravel 5.8 Ajax Crud Tutorial using DataTables with an example.

Server side Laravel DataTables example

There are the Following The simple About Server side Laravel DataTables example Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to implement DataTables server-side in laravel, so the datatables jquery plugin with php mysql and bootstrap for this example is following below.

Create Laravel 5.8 View


<!DOCTYPE html>
<title>Laravel 5.8 - DataTables Server-side Processing</title>
<link rel="stylesheet" type="text/css" href=""/>
 <div class="row">
    <div class="col-md-12">
               <table class="table table-bordered" id="products">
                           <th>Created At</th>
<script src=""></script>
<script type="text/javascript" src=""></script>
    $(document).ready(function () {
            "processing": true,
            "serverSide": true,
                     "url": "{{ url('allproducts') }}",
                     "dataType": "json",
                     "type": "POST",
                     "data":{ _token: "{{csrf_token()}}"}
            "columns": [
                { "data": "id" },
                { "data": "title" },
                { "data": "body" },
                { "data": "created_at" },
                { "data": "options" }


Create Laravel Model, controller and route

Create Laravel Route

Route::post('allproducts', '[email protected]' )->name('allproducts');

The Product model code is given below.



namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model

Now the code for allproduct function in productController.

Create Laravel Controller



public function allproducts(Request $request)
        $columns = array( 
                            0 =>'id', 
                            1 =>'title',
                            2=> 'body',
                            3=> 'created_at',
                            4=> 'id',
        $totalData = Product::count();
        $totalFiltered = $totalData; 

        $limit = $request->input('length');
        $start = $request->input('start');
        $order = $columns[$request->input('order.0.column')];
        $dir = $request->input('order.0.dir');
            $products = Product::offset($start)
        else {
            $search = $request->input('search.value'); 

            $products =  Product::where('id','LIKE',"%{$search}%")
                            ->orWhere('title', 'LIKE',"%{$search}%")

            $totalFiltered = Product::where('id','LIKE',"%{$search}%")
                             ->orWhere('title', 'LIKE',"%{$search}%")

        $data = array();
            foreach ($products as $product)
                $show =  route('',$product->id);
                $edit =  route('products.edit',$product->id);

                $all_products_data['id'] = $product->id;
                $all_products_data['title'] = $product->title;
                $all_products_data['body'] = substr(strip_tags($product->body),0,50)."...";
                $all_products_data['created_at'] = date('j M Y h:i a',strtotime($product->created_at));
                $all_products_data['options'] = " <a href='{$show}' title='SHOW' ><span class='glyphicon glyphicon-list'></span></a>
                                           <a href='{$edit}' title='EDIT' ><span class='glyphicon glyphicon-edit'></span></a>";
                $data[] = $all_products_data;

        $json_data = array(
                    "draw"            => intval($request->input('draw')),  
                    "recordsTotal"    => intval($totalData),  
                    "recordsFiltered" => intval($totalFiltered), 
                    "data"            => $data   
        echo json_encode($json_data); 

Web Programming Tutorials Example with Demo

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Server side Laravel DataTables example.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1.   Jquery Get Number of Characters String length
  2.   wheredate in laravel | Eloquent date filtering : whereDate()
  3.   Laravel 5.8 Datatables Server Side Processing
  4.   How to Solve Error call to a member function toArray() on null?
  5.   JavaScript setInterval and clearInterval function
  6.   PayPal Payment Gateway with PHP MySQL Database
  7.   Jquery Datatable listing json Server side in Php Mysql and Ajax
  8.   DataTables Pagination Server-side Processing using PHP and MySQL
  9.   DataTables Column Search Server side processing in PHP
  10.   WordPress Create Plugin From Scratch