PHPackages                             eadortsu/eloquent-datatable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. eadortsu/eloquent-datatable

ActiveLibrary[Database &amp; ORM](/categories/database)

eadortsu/eloquent-datatable
===========================

Eloquent DataTable plugin for server side ajax call handling.

0.1.5(10y ago)042MITPHPPHP &gt;=5.4.0

Since Apr 12Pushed 5y agoCompare

[ Source](https://github.com/eadortsu/EloquentDataTable)[ Packagist](https://packagist.org/packages/eadortsu/eloquent-datatable)[ RSS](/packages/eadortsu-eloquent-datatable/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

EloquentDataTable [![Build status](https://camo.githubusercontent.com/cca56133b4a138509c5bdfc558130a3d85b50ca66a1dd47a0bff9218e00157ed/68747470733a2f2f7472617669732d63692e6f72672f4c697665436f6e74726f6c2f456c6f7175656e74446174615461626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/LiveControl/EloquentDataTable)
========================================================================================================================================================================================================================================================================================================================================

[](#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](https://www.datatables.net/) this is what you are looking for.

Usage
-----

[](#usage)

### Step 1: Install through composer

[](#step-1-install-through-composer)

`composer require livecontrol/eloquent-datatable`

### Step 2: Add DataTables javascript and set it up

[](#step-2-add-datatables-javascript-and-set-it-up)

For more information check out the [datatables manual](http://datatables.net/manual/index). Make sure you have [csrf requests](http://laravel.com/docs/master/routing#csrf-protection) working with jquery ajax calls.

```
var table = $('#example').DataTable({
  "processing": true,
  "serverSide": true,
  "ajax": {
    "url": "",
    "type": "POST"
  }
});
```

### Step 3: Use it

[](#step-3-use-it)

```
$users = new Models\User();
$dataTable = new LiveControl\EloquentDataTable\DataTable($users, ['email', 'firstname', 'lastname']);
echo json_encode($dataTable->make());
```

### Optional step 4: Set versions of DataTables plugin.

[](#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 LiveControl\EloquentDataTable\VersionTransformers\Version109Transformer());
```

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

Examples
--------

[](#examples)

- [Basic setup](#basic-example)
- [Combining columns](#combining-columns)
- [Using raw column queries](#using-raw-column-queries)
- [Return custom row format](#return-custom-row-format)
- [Showing results with relations](#showing-results-with-relations)

### Basic example

[](#basic-example)

```
use LiveControl\EloquentDataTable\DataTable;

class UserController {
  ...
  public function datatable()
  {
    $users = new User();
    $dataTable = new DataTable(
      $users->where('city', '=', 'London'),
      ['email', 'firstname', 'lastname']
    );

    return $dataTable->make();
  }
}
```

In this case we are making a datatable response with all users who live in London.

### Combining columns

[](#combining-columns)

If you want to combine the firstname and lastname into one column, you can wrap them into an array.

```
use LiveControl\EloquentDataTable\DataTable;

class UserController {
  ...
  public function datatable()
  {
    $users = new User();
    $dataTable = new DataTable(
      $users,
      ['email', ['firstname', 'lastname'], 'city']
    );

    return $dataTable->make();
  }
}
```

### Using raw column queries

[](#using-raw-column-queries)

Sometimes you want to use custom sql statements on a column to get specific results, this can be achieved using the `ExpressionWithName` class.

```
use LiveControl\EloquentDataTable\DataTable;
use LiveControl\EloquentDataTable\ExpressionWithName;

class UserController {
  ...
  public function datatable()
  {
    $users = new User();
    $dataTable = new DataTable(
      $users,
      [
        'email',
        new ExpressionWithName('`id` + 1000', 'idPlus1000'),
        'city'
      ]
    );

    return $dataTable->make();
  }
}
```

### Return custom row format

[](#return-custom-row-format)

If you would like to return a custom row format you can do this by adding an anonymous function as an extra argument to the make method.

```
use LiveControl\EloquentDataTable\DataTable;

class UserController {
  ...
  public function datatable()
  {
    $users = new User();
    $dataTable = new DataTable($users, ['id', ['firstname', 'lastname'], 'email', 'city']);

    $dataTable->setFormatRowFunction(function ($user) {
      return [
        $user->id,
        '' . $user->firstnameLastname . '',
        '' . $user->email . '',
        $user->city,
        '&times;'
      ];
    });

    return $dataTable->make();
  }
}
```

### Showing results with relations

[](#showing-results-with-relations)

```
use LiveControl\EloquentDataTable\DataTable;

class UserController {
  ...
  public function datatable()
  {
    $users = new User();
    $dataTable = new DataTable(
    	$users->with('country'),
    	['name', 'country_id', 'email', 'id']
    );

    $dataTable->setFormatRowFunction(function ($user) {
    	return [
    		''.$user->name.'',
    		$user->country->name,
    		''.$user->email.'',
    		'&times;'
    	];
    });

    return $dataTable->make();
  }
}
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~52 days

Total

4

Last Release

3889d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/40460447?v=4)[Eugene Adortsu](/maintainers/eadortsu)[@eadortsu](https://github.com/eadortsu)

---

Top Contributors

[![jeffreydevreede](https://avatars.githubusercontent.com/u/2203546?v=4)](https://github.com/jeffreydevreede "jeffreydevreede (33 commits)")[![mayeulak](https://avatars.githubusercontent.com/u/19293023?v=4)](https://github.com/mayeulak "mayeulak (2 commits)")[![eadortsu](https://avatars.githubusercontent.com/u/40460447?v=4)](https://github.com/eadortsu "eadortsu (1 commits)")[![ikhsan017](https://avatars.githubusercontent.com/u/1480166?v=4)](https://github.com/ikhsan017 "ikhsan017 (1 commits)")

---

Tags

laraveleloquentdatatable

### Embed Badge

![Health badge](/badges/eadortsu-eloquent-datatable/health.svg)

```
[![Health](https://phpackages.com/badges/eadortsu-eloquent-datatable/health.svg)](https://phpackages.com/packages/eadortsu-eloquent-datatable)
```

###  Alternatives

[silber/bouncer

Eloquent roles and abilities.

3.6k4.4M24](/packages/silber-bouncer)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M46](/packages/watson-validating)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
