PHP code example of livecontrol / eloquent-datatable
1. Go to this page and download the library: Download livecontrol/eloquent-datatable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
livecontrol / eloquent-datatable example snippets
$users = new Models\User();
$dataTable = new LiveControl\EloquentDataTable\DataTable($users, ['email', 'firstname', 'lastname']);
echo json_encode($dataTable->make());
use LiveControl\EloquentDataTable\DataTable;
class UserController {
...
public function datatable()
{
$users = new User();
$dataTable = new DataTable(
$users->where('city', '=', 'London'),
['email', 'firstname', 'lastname']
);
return $dataTable->make();
}
}
use LiveControl\EloquentDataTable\DataTable;
class UserController {
...
public function datatable()
{
$users = new User();
$dataTable = new DataTable(
$users,
['email', ['firstname', 'lastname'], 'city']
);
return $dataTable->make();
}
}
use LiveControl\EloquentDataTable\DataTable;
use LiveControl\EloquentDataTable\ExpressionWithName;
class UserController {
...
public function datatable()
{
$users = new User();
$dataTable = new DataTable(
$users,
[
'email',
new ExpressionWithName('`id` + 1000', 'idPlus1000'),
'city'
]
);
return $dataTable->make();
}
}