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.

Add Columns

Add mutated / hidden columns.

Add hidden model columns

use DataTables;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return DataTables::eloquent($model)
->addColumns(['foo','bar','buzz'=>"red"])
->toJson();
});

Example Response

{
"draw": 2,
"recordsTotal": 10,
"recordsFiltered": 3,
"data": [{
"id": 476,
"name": "Esmeralda Kulas",
"email": "[email protected]",
"created_at": "2016-07-31 23:26:14",
"updated_at": "2016-07-31 23:26:14",
"deleted_at": null,
"superior_id": 0,
"foo":"value",
"bar":"value",
"buzz":"red"
}, {
"id": 6,
"name": "Zachery Muller",
"email": "[email protected]",
"created_at": "2016-07-31 23:25:43",
"updated_at": "2016-07-31 23:25:43",
"deleted_at": null,
"superior_id": 1,
"foo":"value",
"bar":"value",
"buzz":"red"
}]
}