You may use Laravel's Query Builder as data source for your dataTables.
You can look at Yajra\DataTables\QueryDataTable
class which handles the conversion of your Query Builder into a readable DataTable API response.
use DB;
use DataTables;
Route::get('user-data', function() {
$query = DB::table('users');
return DataTables::of($query)->toJson();
});
use DB;
use DataTables;
Route::get('user-data', function() {
$query = DB::table('users');
return DataTables::queryBuilder($query)->toJson();
});
use DB;
use Yajra\DataTables\DataTables;
Route::get('user-data', function(DataTables $dataTables) {
$query = DB::table('users');
return $dataTables->queryBuilder($query)->toJson();
});
use DB;
Route::get('user-data', function() {
$query = DB::table('users');
return app('datatables')->queryBuilder($query)->toJson();
});
use Yajra\DataTables\QueryDataTable;
Route::get('user-data', function() {
$query = DB::table('users');
return (new QueryDataTable($query))->toJson();
});