Laravel Eloquent DataTables

Feature Overview:

  • Array & Object Response
  • Eager Loading
  • Nested Eager Loading
  • Soft Deletes Trait
  • Query Scopes

Important Notes

Searching & Sorting on Eager Loaded Models

When searching/sorting for eager loaded models, your column name must be declared like relation.column

columns: [{data: 'id', name: ''}, {data: '', name: ''}]

Relation Response Behavior

If your relations consists of (2) two or more words, the convention to use is as follows:

{data: 'relation_name.column', name: 'relationName.column'}

Selecting Fields

It is advised that you include select('table.*') on query to avoid weird issues where id from related model replaces the id of the main model.

$posts = Post::with('user')->select('posts.*');