-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRolePermissionsInfo.php
50 lines (43 loc) · 1.37 KB
/
RolePermissionsInfo.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
<?php
namespace App\Livewire\Crew;
use App\Actions\Permissions\ReadPermissionConfig;
use Illuminate\View\View;
use Livewire\Component;
use LivewireUI\Modal\ModalComponent;
use Spatie\Permission\Models\Role;
class RolePermissionsInfo extends ModalComponent
{
public $role;
protected ReadPermissionConfig $readPermissionConfig;
public $permissionsForRole = [];
/**
* Initializes the component
* @param $role
* @return void
*/
public function mount($role)
{
$this->role = Role::find($role);
$this->readPermissionConfig = new ReadPermissionConfig();
$permissionsData = $this->readPermissionConfig->execute('config/permissions.yml');
foreach ($permissionsData['permissions'] as $entity => $actions) {
foreach ($actions as $action => $rolesWithPermission) {
if (!is_array($rolesWithPermission)) {
$rolesWithPermission = [$rolesWithPermission];
}
if (in_array($this->role->name, $rolesWithPermission)) {
// Group permissions by entity
$this->permissionsForRole[$entity][] = $action;
}
}
}
}
/**
* Renders the component
* @return View
*/
public function render(): View
{
return view('livewire.crew.role-permissions-info');
}
}