Server Side Data Table Implementation In Laravel.

In this tutorial, We will learn how to implement Datatables with server side processing in Laravel. Here we will get data from MySQL database through ajax in Laravel. Datatables helps in adding sorting, paging and filtering abilities to plain HTML tables with minimal effort. The main goal is to enhance the accessibility of data in normal HTML tables.

Below are the steps to implement Datatables in Laravel.

Install Laravel.

In this step, we will install Laravel application if not installed already .Run below command to install Laravel application.

composer create-project –prefer-dist laravel/laravel demo

Install Yajra Datatable

Run the following command to install yajra datatable package for datatable.

composer require yajra/laravel-datatables-oracle

Set the providers and alias in config/app.php.

‘providers’ => [
‘aliases’ => [
‘DataTables’ => YajraDataTablesFacadesDataTables::class,

Add Route

Route::get(‘table’, ‘[email protected]’)->name(‘table’);

Create Controller.


namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppProduct;
use DataTables;
class ProductController extends Controller

public function getData(Request $request){

if ($request->ajax()) {
$datas = Product::all();
return Datatables::of($datas)->make();
return view(‘products’);

Create Model


namespace App;
use IlluminateDatabaseEloquentModel;
class Product extends Model

Create View

<!DOCTYPE html>
<title>Laravel Datatables Server Side Data Processing Example –</title>
<meta name=”csrf-token” content=”{{ csrf_token() }}”>
<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”>
<h5>Laravel Datatables Server Side Data Processing Example</h5>
<table class=”table table-bordered data-table”>


<script type=”text/javascript”>
$(function () {

var table = $(‘.data-table’).DataTable({
processing: true,
serverSide: true,
ajax: “{{ route(‘table’) }}”,
columns: [
{data: ‘p_id’, name: ‘p_id’},
{data: ‘name’, name: ‘name’},
{data: ‘price’, name: ‘price’},


The post Server Side Data Table Implementation In Laravel. appeared first on PHPFOREVER.

Flatlogic Admin Templates banner

Leave a Reply

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