#9 EloquentDataTable

Eloquent compatible DataTable plugin for server side ajax call handling. If you are familiar with eloquent and would like to use it in combination with datatables this is what you are looking for.



Step 1: Install through composer

composer require livecontrol/eloquent-datatable

Step 2: Add DataTables javascript and set it up

For more information check out the datatables manual. Make sure you have csrf requests working with jquery ajax calls.

var table = $('#example').DataTable({
  "processing": true,
  "serverSide": true,
  "ajax": {
    "url": "<url to datatable route>",
    "type": "POST"

Step 3: Use it

$users = new ModelsUser();
$dataTable = new LiveControlEloquentDataTableDataTable($users, ['email', 'firstname', 'lastname']);
echo json_encode($dataTable->make());

Optional step 4: Set versions of DataTables plugin.

Just initialize the DataTable object as you would normally and call the setVersionTransformer function as in the following example (for version 1.09 of DataTables):

$dataTable->setVersionTransformer(new LiveControlEloquentDataTableVersionTransformersVersion109Transformer());

By default the plugin will be loading the transformer which is compatible with DataTables version 1.10.