Skip to content

Latest commit

 

History

History
66 lines (47 loc) · 1.28 KB

engine-eloquent.md

File metadata and controls

66 lines (47 loc) · 1.28 KB

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();
});