|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\DataTables; |
|
4
|
|
|
|
|
5
|
|
|
use Yajra\Acl\Models\Permission; |
|
6
|
|
|
use Yajra\Datatables\Services\DataTable; |
|
7
|
|
|
|
|
8
|
|
|
class PermissionsDataTable extends DataTable |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
12
|
|
|
*/ |
|
13
|
|
|
public function ajax() |
|
14
|
|
|
{ |
|
15
|
|
|
return $this->datatables |
|
16
|
|
|
->eloquent($this->query()) |
|
17
|
|
|
->addColumn('roles', function (Permission $permission) { |
|
18
|
|
|
return view('administrator.permissions.datatables.roles', compact('permission'))->render(); |
|
|
|
|
|
|
19
|
|
|
}) |
|
20
|
|
|
->editColumn('system', function (Permission $permission) { |
|
21
|
|
|
return dt_check($permission->system); |
|
22
|
|
|
}) |
|
23
|
|
|
->editColumn('slug', function (Permission $permission) { |
|
24
|
|
|
return '<small>' . $permission->slug . '</small>'; |
|
25
|
|
|
}) |
|
26
|
|
|
->addColumn('action', 'administrator.permissions.datatables.action') |
|
27
|
|
|
->rawColumns(['roles', 'system', 'slug', 'action']) |
|
28
|
|
|
->make(true); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return \Illuminate\Database\Eloquent\Builder |
|
33
|
|
|
*/ |
|
34
|
|
|
public function query() |
|
35
|
|
|
{ |
|
36
|
|
|
return Permission::query(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return \Yajra\Datatables\Html\Builder |
|
41
|
|
|
*/ |
|
42
|
|
|
public function html() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this |
|
45
|
|
|
->builder() |
|
46
|
|
|
->columns($this->getColumns()) |
|
47
|
|
|
->addAction(['width' => '60px']) |
|
48
|
|
|
->parameters($this->getBuilderParameters()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
private function getColumns() |
|
55
|
|
|
{ |
|
56
|
|
|
return [ |
|
57
|
|
|
'id', |
|
58
|
|
|
'resource', |
|
59
|
|
|
'name', |
|
60
|
|
|
'slug', |
|
61
|
|
|
'system' => ['class' => 'text-center', 'width' => '30px', 'title' => 'Sys'], |
|
62
|
|
|
'roles' => [ |
|
63
|
|
|
'class' => 'text-center', |
|
64
|
|
|
'width' => '30px', |
|
65
|
|
|
'searchable' => false, |
|
66
|
|
|
'orderable' => false, |
|
67
|
|
|
'printable' => false, |
|
68
|
|
|
], |
|
69
|
|
|
'created_at', |
|
70
|
|
|
'updated_at', |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get builder params. |
|
76
|
|
|
* |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function getBuilderParameters() |
|
80
|
|
|
{ |
|
81
|
|
|
return array_merge_recursive(['buttons' => ['resource']], [ |
|
82
|
|
|
'order' => [[0, 'desc']], |
|
83
|
|
|
'buttons' => [ |
|
84
|
|
|
[ |
|
85
|
|
|
'extend' => 'create', |
|
86
|
|
|
'text' => '<i class="fa fa-plus"></i> ' . trans('cms::permission.datatable.buttons.create'), |
|
87
|
|
|
], |
|
88
|
|
|
'export', |
|
89
|
|
|
'print', |
|
90
|
|
|
'reset', |
|
91
|
|
|
'reload', |
|
92
|
|
|
], |
|
93
|
|
|
'stateSave' => true, |
|
94
|
|
|
]); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Get filename for export. |
|
99
|
|
|
* |
|
100
|
|
|
* @return string |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function filename() |
|
103
|
|
|
{ |
|
104
|
|
|
return 'permissions'; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: