Server-side processing Laravel DataTables

Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

Today, We want to share with you Server-side processing Laravel DataTables.In this post we will show you How to implement DataTables server-side in laravel 5.8, hear for Datatables Server Side Processing in Laravel 5.8 we will give you demo and example for implement.In this post, we will learn about Laravel 5.8 – DataTables Server-side Processing with an example.

Server-side processing Laravel DataTables

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

As I will cover this Post with live Working example to develop jQuery Datatables and Laravel Server-side implementation, so the laravel datatables large data structures for this example is following below.

Read Also:  Laravel update multiple rows with different values


This example is a bit more comlex since I have columns that are foreign keys of the product table.

use Illuminate\Pagination\Paginator;

public function index(Request $request)
    if($request->ajax()) {
        $columns     = ['', 'member_name', 'location', 'category_name', 'status_name', 'date'];
        $draw        = $request->draw;
        $start       = $request->start; 
        $length      = $request->length;
        $column      = $request->order[0]['column'];
        $dir         = $request->order[0]['dir'];
        $searchValue = $request->search['value'];
        //Sets the current page
        Paginator::currentPageResolver(function () use ($start, $length) {
            return ($start / $length + 1);
        $products = Product::whereHas('member', function($query) use ($searchValue) {
            $query->where('name', 'like', '%'.$searchValue.'%');
        ->orWhereHas('location', function($query) use ($searchValue) {
            $query->where('location', 'like', '%'.$searchValue.'%');
        ->orWhereHas('category', function($query) use ($searchValue) {
            $query->where('name', 'like', '%'.$searchValue.'%');
        ->orWhereHas('status', function($query) use ($searchValue) {
            $query->where('name', 'like', '%'.$searchValue.'%');
        ->orWhere('', 'like', '%'.$searchValue.'%')
        ->orWhere('date', 'like', '%'.str_replace('/', '-', $searchValue).'%')
        ->leftJoin('members', 'products.member_id', '=', '')
        ->leftJoin('locations', 'products.location_id', '=', '')
        ->leftJoin('categories', 'products.category_id', '=', '')
        ->leftJoin('statuses', 'products.status_id', '=', '')
        ->select(' as member_name', 'products.*', 'locations.location', ' as category_name', ' as status_name')
        ->orderBy($columns[$column], $dir)
        return [
            'draw' => $draw,
            'recordsTotal' => $products->total(),
            'recordsFiltered' => $products->total(),
            'data' => $products
    return view('product/index');


Read Also:  DataTable Custom Filter Server Side Examples

Just so you can get the idea, your data might be different. Note that I changed the dataSrc to fit the data we return.

var table = $('table.products-table').DataTable({
    processing: true,
    serverSide: true,
    lengthChange: true,
    "ajax": {
        "url": '/products',
        "dataSrc": ""
    "columns": [
        { "data": "id", "name": "id",
            fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
                $(nTd).html("<a href='/products/""'>""</a>");
        { "data": "member_name", "name": "member_name",
            fnCreatedCell: function (nTd, sData, oData, iRow, iCol) {
                if(oData.member_name) {
                    $(nTd).html("<a href='/members/"+oData.member_id+"'>"+oData.member_name+"</a>");
        { "data": "location", "name": "location", "defaultContent": "" },
        { "data": "category_name", "name": "category_name" },
        { "data": "status_name", "name": "status_name" },
        { "data": "date", "name": "date" },
    dom: '<Blf<t>ip>',
    order: [ [0, 'desc'] ],
    buttons: [
            extend: 'excelHtml5',
            title: 'Data export'
            extend: 'pdfHtml5',
            title: 'Data export'
    pageLength: 25,
    lengthMenu: [25, 50, 75, 100],
    initComplete: function(settings, json) {
         table.buttons().container().appendTo( '.colsm6:eq(0)', table.table().container() );

Web Programming Tutorials Example with Demo

Read :

Read Also:  Ajax Image Upload without Refreshing Page using Jquery


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

I hope you get an idea about Server-side processing Laravel DataTables.
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.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

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