1
|
|
|
<?php |
2
|
|
|
namespace Afrittella\BackProject\Repositories; |
3
|
|
|
|
4
|
|
|
class Roles extends Base |
5
|
|
|
{ |
6
|
|
|
public function model() |
7
|
|
|
{ |
8
|
|
|
return config('laravel-permission.models.role'); |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
public function create(array $data) |
12
|
|
|
{ |
13
|
|
|
$role = $this->model->create($data); |
|
|
|
|
14
|
|
|
|
15
|
|
|
if (!empty($data['permissions'])) { |
16
|
|
|
$role->permissions()->sync($data['permissions']); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
return $role; |
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['permissions'])) { |
26
|
|
|
$model_data->permissions()->sync($data['permissions']); |
27
|
|
|
} |
28
|
|
|
return $model_data->update($data); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Transform data in a table array for view |
33
|
|
|
* @param $data |
34
|
|
|
* @param array $options |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function transform($data = [], $options = []) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
if (empty($data)) { |
40
|
|
|
$data = $this->all(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// Table header |
44
|
|
|
$head = [ |
45
|
|
|
'columns' => [ |
46
|
|
|
trans('back-project::roles.name'), |
47
|
|
|
trans('back-project::roles.permissions'), |
48
|
|
|
trans('back-project::crud.actions'), |
49
|
|
|
] |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
$body = []; |
53
|
|
|
|
54
|
|
|
foreach ($data as $row): |
55
|
|
|
$actions = []; |
56
|
|
|
|
57
|
|
|
if ($row->name !== 'administrator' and $row->name !== 'user') { |
|
|
|
|
58
|
|
|
$actions = [ |
59
|
|
|
'edit' => ['url' => route('bp.roles.edit', [$row['id']])], //url('/admin/users/edit', [$row['id']])], |
|
|
|
|
60
|
|
|
'delete' => ['url' => route('bp.roles.delete', [$row['id']])] |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$body[] = [ |
65
|
|
|
'columns' => [ |
66
|
|
|
['content' => $row->name], |
67
|
|
|
['content' => implode('<br>', $row->permissions->pluck('name')->toArray())], |
68
|
|
|
['content' => false, 'actions' => $actions], |
69
|
|
|
] |
70
|
|
|
]; |
71
|
|
|
endforeach; |
72
|
|
|
|
73
|
|
|
return [ |
74
|
|
|
'head' => $head, |
75
|
|
|
'body' => $body |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
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.