Skip to content
Icon

WARNING You're browsing the documentation for an old version of LARAVEL-DATATABLES. Consider upgrading your project to laravel-datatables 11.0.

Eloquent Data Source

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

Eloquent via Factory

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

Eloquent via Facade

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

Eloquent via Dependency Injection

use Yajra\Datatables\Datatables;
 
Route::get('user-data', function(Datatables $datatables) {
$model = App\User::query();
 
return $datatables->eloquent($model)->make(true);
});

Eloquent via IoC

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