|
1
|
|
|
<?php |
|
2
|
|
|
namespace Afrittella\BackProject\Repositories; |
|
3
|
|
|
|
|
4
|
|
|
class Permissions extends Base |
|
5
|
|
|
{ |
|
6
|
|
|
public function model() |
|
7
|
|
|
{ |
|
8
|
|
|
return config('laravel-permission.models.permission'); |
|
9
|
|
|
} |
|
10
|
|
|
|
|
11
|
|
|
public function create(array $data) |
|
12
|
|
|
{ |
|
13
|
|
|
$permission = $this->model->create($data); |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
if (!empty($data['roles'])) { |
|
16
|
|
|
$permission->roles()->sync($data['roles']); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
return $permission; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
View Code Duplication |
public function update(array $data, $id, $attribute = 'id') |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
$model_data = $this->findBy($attribute, $id); |
|
25
|
|
|
if (!empty($data['roles'])) { |
|
26
|
|
|
$model_data->roles()->sync($data['roles']); |
|
27
|
|
|
} |
|
28
|
|
|
return $model_data->update($data); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function firstOrCreate($data) |
|
32
|
|
|
{ |
|
33
|
|
|
// If permissions are in format permission1,permission2... |
|
34
|
|
|
if (!is_array($data)) { |
|
35
|
|
|
$perms = explode(',', $data); |
|
36
|
|
|
} else { |
|
37
|
|
|
$perms = $data; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
foreach ($perms as $perm): |
|
41
|
|
|
$this->model->firstOrCreate([ |
|
42
|
|
|
'name' => trim(strtolower($perm)) |
|
43
|
|
|
]); |
|
44
|
|
|
endforeach; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Transform data in a table array for view |
|
49
|
|
|
* @param $data |
|
50
|
|
|
* @param array $options |
|
51
|
|
|
* @return array |
|
52
|
|
|
*/ |
|
53
|
|
View Code Duplication |
public function transform($data = [], $options = []) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
if (empty($data)) { |
|
56
|
|
|
$data = $this->all(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
// Table header |
|
60
|
|
|
$head = [ |
|
61
|
|
|
'columns' => [ |
|
62
|
|
|
trans('back-project::permissions.name'), |
|
63
|
|
|
trans('back-project::permissions.roles'), |
|
64
|
|
|
trans('back-project::crud.actions'), |
|
65
|
|
|
] |
|
66
|
|
|
]; |
|
67
|
|
|
|
|
68
|
|
|
$body = []; |
|
69
|
|
|
|
|
70
|
|
|
foreach ($data as $row): |
|
71
|
|
|
$actions = []; |
|
72
|
|
|
|
|
73
|
|
|
if ($row->name !== 'administration' and $row->name !== 'backend') { |
|
|
|
|
|
|
74
|
|
|
$actions = [ |
|
75
|
|
|
'edit' => ['url' => route('bp.permissions.edit', [$row['id']])], |
|
76
|
|
|
'delete' => ['url' => route('bp.permissions.delete', [$row['id']])] |
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$body[] = [ |
|
81
|
|
|
'columns' => [ |
|
82
|
|
|
['content' => $row->name], |
|
83
|
|
|
['content' => implode('<br>', $row->roles->pluck('name')->toArray())], |
|
84
|
|
|
['content' => false, 'actions' => $actions], |
|
85
|
|
|
] |
|
86
|
|
|
]; |
|
87
|
|
|
endforeach; |
|
88
|
|
|
|
|
89
|
|
|
return [ |
|
90
|
|
|
'head' => $head, |
|
91
|
|
|
'body' => $body |
|
92
|
|
|
]; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
} |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.