Skip to content
Icon

WARNING You're browsing the documentation for an upcoming version of Laravel DataTables. The documentation and features of this release are subject to change.

Eloquent Data Source

You may use Laravel's Eloquent Model as data source for your dataTables. You can look at Yajra\DataTables\EloquentDataTable class which handles the conversion of your Eloquent Model into a readable DataTable API response.

Eloquent via Factory

use DataTables;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return DataTables::of($model)->toJson();
});

Eloquent via Facade

use DataTables;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return DataTables::eloquent($model)->toJson();
});

Eloquent via Dependency Injection

use Yajra\DataTables\DataTables;
 
Route::get('user-data', function(DataTables $dataTables) {
$model = App\User::query();
 
return $dataTables->eloquent($model)->toJson();
});

Eloquent via IoC

Route::get('user-data', function() {
$model = App\User::query();
 
return app('datatables')->eloquent($model)->toJson();
});

EloquentDataTable new Instance

use Yajra\DataTables\EloquentDataTable;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return (new EloquentDataTable($model))->toJson();
});