You may use Laravel's Collection as data source for your dataTables.
You can look at Yajra\DataTables\CollectionDataTable
class which handles the conversion of your Collection into a readbale DataTable API response.
use DataTables;
Route::get('user-data', function() {
$collection = collect([
['id' => 1, 'name' => 'John'],
['id' => 2, 'name' => 'Jane'],
['id' => 3, 'name' => 'James'],
]);
return DataTables::of($collection)->toJson();
});
use DataTables;
Route::get('user-data', function() {
$collection = collect([
['id' => 1, 'name' => 'John'],
['id' => 2, 'name' => 'Jane'],
['id' => 3, 'name' => 'James'],
]);
return DataTables::collection($collection)->toJson();
});
use Yajra\DataTables\DataTables;
Route::get('user-data', function(DataTables $dataTables) {
$collection = collect([
['id' => 1, 'name' => 'John'],
['id' => 2, 'name' => 'Jane'],
['id' => 3, 'name' => 'James'],
]);
return $dataTables->collection($collection)->toJson();
});
Route::get('user-data', function() {
$collection = collect([
['id' => 1, 'name' => 'John'],
['id' => 2, 'name' => 'Jane'],
['id' => 3, 'name' => 'James'],
]);
return app('datatables')->collection($collection)->toJson();
});
use Yajra\DataTables\CollectionDataTable;
Route::get('user-data', function() {
$collection = App\User::all();
return (new CollectionDataTable($collection))->toJson();
});