Skip to content

Commit

Permalink
fix: creating a role with permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Bak committed Aug 21, 2024
1 parent a273afd commit 7402dd2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/Livewire/Admin/Roles/CreateRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CreateRole extends ModalComponent
use LivewireAlert;

public string $name = '';

public array $rolePermissions = [];

// set validation rules
Expand Down Expand Up @@ -42,7 +43,12 @@ public function create(): void
'name' => $this->name,
]);

$role->syncPermissions($this->rolePermissions);
$permissions = collect($this->rolePermissions)->map(function ($permission) use ($role) {
// convert string to int
return (int) $permission;
})->toArray();

$role->syncPermissions($permissions);

$this->alert('success', 'Role Created Successfully!');

Expand Down

0 comments on commit 7402dd2

Please sign in to comment.