1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Domains\Roles; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Log; |
6
|
|
|
|
7
|
|
|
use App\UserRolePermissions; |
8
|
|
|
|
9
|
|
|
use App\UserRoleType; |
10
|
|
|
|
11
|
|
|
class SetPermissions |
12
|
|
|
{ |
13
|
6 |
|
public function submitRole($request) |
14
|
|
|
{ |
15
|
6 |
|
if($request->role_id != null) |
16
|
|
|
{ |
17
|
2 |
|
$this->updateRole($request); |
18
|
|
|
} |
19
|
|
|
else |
20
|
|
|
{ |
21
|
4 |
|
$this->createRole($request); |
22
|
|
|
} |
23
|
|
|
|
24
|
6 |
|
return true; |
25
|
|
|
} |
26
|
|
|
|
27
|
2 |
|
protected function updateRole($request) |
28
|
|
|
{ |
29
|
2 |
|
UserRoleType::findOrFail($request->role_id)->update([ |
30
|
2 |
|
'name' => $request->name, |
31
|
2 |
|
'description' => $request->description, |
32
|
|
|
]); |
33
|
|
|
|
34
|
2 |
|
foreach($request->user_role_permissions as $perm) |
35
|
|
|
{ |
36
|
2 |
|
Log::emergency($perm); |
37
|
2 |
|
UserRolePermissions::where('role_id', $request->role_id)->where('perm_type_id', $perm['perm_type_id'])->update([ |
38
|
2 |
|
'allow' => $perm['allow'], |
39
|
|
|
]); |
40
|
|
|
} |
41
|
2 |
|
} |
42
|
|
|
|
43
|
4 |
|
protected function createRole($request) |
44
|
|
|
{ |
45
|
4 |
|
$role = UserRoleType::create([ |
46
|
4 |
|
'name' => $request->name, |
47
|
4 |
|
'description' => $request->description, |
48
|
|
|
]); |
49
|
|
|
|
50
|
4 |
|
foreach($request->user_role_permissions as $perm) |
51
|
|
|
{ |
52
|
4 |
|
UserRolePermissions::create([ |
53
|
4 |
|
'role_id' => $role['role_id'], |
54
|
4 |
|
'perm_type_id' => $perm['perm_type_id'], |
55
|
4 |
|
'allow' => isset($perm['allow']) ? true : false, |
56
|
|
|
]); |
57
|
|
|
} |
58
|
4 |
|
} |
59
|
|
|
} |
60
|
|
|
|