$ composer require ad-mos/laravel-datatables
1 - Simple table:
public function data(DataTables $dataTables)
{
return $dataTables->provide(new User);
}
2 - Table with joins:
public function data(DataTables $dataTables)
{
$model = new User;
$query = $model->newQuery()
->leftJoin('user_emails', 'user_emails.user_id', '=', 'users.id')
->leftJoin('user_phones', 'user_phones.user_id', '=', 'users.id')
->groupBy('users.id');
$aliases = [
'emails' => 'GROUP_CONCAT(DISTINCT `user_emails`.email SEPARATOR \'|\')',
'phones' => 'GROUP_CONCAT(DISTINCT `user_phones`.phone SEPARATOR \'|\')',
];
return $dataTables->provide($this->model, $query, $aliases);
}
DataTables can be accessed through IoC, helper or facade:
return $dataTables->provide(...);
return datatables()->provide(...);
return \DataTables::provide(...);
The MIT License. More information here.