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.

Query Builder Data Source

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

Query Builder via Factory

use DB;
use Datatables;
 
Route::get('user-data', function() {
$query = DB::table('users');
 
return Datatables::of($query)->make(true);
});

Query Builder via Facade

use DB;
use Datatables;
 
Route::get('user-data', function() {
$query = DB::table('users');
 
return Datatables::queryBuilder($query)->make(true);
});

Query Builder via Dependency Injection

use DB;
use Yajra\Datatables\Datatables;
 
Route::get('user-data', function(Datatables $datatables) {
$query = DB::table('users');
 
return $datatables->queryBuilder($query)->make(true);
});

Query Builder via IoC

use DB;
 
Route::get('user-data', function() {
$query = DB::table('users');
 
return app('datatables')->queryBuilder($query)->make(true);
});