-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRoleDataTable.php
91 lines (84 loc) · 2.29 KB
/
RoleDataTable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace App\DataTables;
use Spatie\Permission\Models\Role;
use Yajra\DataTables\Services\DataTable;
use Yajra\DataTables\EloquentDataTable;
class RoleDataTable extends DataTable
{
/**
* Build DataTable class.
*
* @param mixed $query Results from query() method.
* @return \Yajra\DataTables\DataTableAbstract
*/
public function dataTable($query)
{
$dataTable = new EloquentDataTable($query);
return $dataTable
->editColumn('default', function ($role) {
return getBooleanColumn($role, 'default');
})
->addColumn('action', 'settings.roles.datatables_actions')
->rawColumns(['action','default']);
}
/**
* Get query source of dataTable.
*
* @param \App\Models\Post $model
* @return \Illuminate\Database\Eloquent\Builder
*/
public function query(Role $model)
{
return $model->newQuery();
}
/**
* Optional method if you want to use html builder.
*
* @return \Yajra\DataTables\Html\Builder
*/
public function html()
{
return $this->builder()
->columns($this->getColumns())
->minifiedAjax()
->addAction(['title'=>trans('lang.actions'),'width' => '80px', 'printable' => false ,'responsivePriority'=>'100'])
->parameters(array_merge(
config('datatables-buttons.parameters'), [
'language' => json_decode(
file_get_contents(base_path('resources/lang/'.app()->getLocale().'/datatable.json')
),true)
]
));
}
/**
* Get columns.
*
* @return array
*/
protected function getColumns()
{
return [
[
'data' => 'name',
'title' => trans('lang.role_name')
],
[
'data' => 'guard_name',
'title' => trans('lang.role_guard_name')
],
[
'data' => 'default',
'title' => trans('lang.role_default')
]
];
}
/**
* Get filename for export.
*
* @return string
*/
protected function filename()
{
return 'rolesdatatable_' . time();
}
}