Laravel Datatables Server Side Search and Pagination Example




Laravel Datatables Server Side Search and Pagination Example

Hello Friends,

Today, I am going show you datatable server side example in laravel.We will implement datatable server side in laravel appliation.There are many ways to get your data into DataTables, and if you are working with seriously large databases, you might want to consider using the server-side options that DataTables provides.

Server-side processing is enabled by setting the serverSide option to true and providing an Ajax data source through the ajax option.

Here I will give you full example for datatable server side example in laravel, So Let's follow the bellow step by step.

Step 1 : Install Laravel App

In this step, You can install laravel fresh app. So open terminal and put the bellow command.

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

Step 2 : Setup Database Configuration

After successfully install laravel app thenafter configure databse setup. We will open ".env" file and change the database name, username and password in the env file.







Step 3 : Create Route

now, we need to add for HomeController in laravel application. so open your "routes/web.php" file and add following route.


Route::get('server-side', 'HomeController@getServerSide')->name('server.side.index');

Step 4 : Create Controler

Here this step now we should create new controller as HomeController. So run bellow command and create new controller.

php artisan make:controller HomeController

successfully run above command then,you can create method for get courses and fetch record users table. So Let's copy bellow and put in the controller file.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

use Yajra\DataTables\DataTables;

class HomeController extends Controller


public function getServerSide(Request $request)


if ($request->ajax()) {

$users = User::select('*');

return Datatables::of($users)->make(true);


return view('serverSide');



Step 5 : Create Blade File

In last step. In this step we have to create blade file. So mainly we have to create server side datatable view file for show serverside. So finally you have to create following file and put bellow code:


<!DOCTYPE html>



<title>laravel datatables server side example</title>

<link rel="stylesheet" href="" />

<link href="" rel="stylesheet">

<link href="" rel="stylesheet">

<script src=""></script>

<script src=""></script>

<script src=""></script>

<script src=""></script>

<script src=""></script>



<div class="container" style="margin-top: 100px;margin-bottom: 100px; ">

<div class="row justify-content-center">

<div class="col-md-8">

<div class="card">

<div class="card-header bg-info text-white"><h5>Laravel Datatables Server Side Example -</h5></div>

<div class="card-body">

<table class="data-table mdl-data-table dataTable" cellspacing="0" width="100%" role="grid" style="width: 100%;">

















<script type="text/javascript">

$(document).ready(function() {


processing: true,

serverSide: true,

ajax: "{{ route('server.side.index') }}",

columns: [

{ "data": "id" },

{ "data": "name" },

{ "data": "email" },

{ "data": "gender" },







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

php artisan serve

Now you can open bellow URL on your browser:


It will help you...

#Laravel 7


#Laravel 6