Closed ITango closed 4 years ago
Same here :)
One way to achieve this would be to make a viewOnly field that uses the getPermissionsViaRoles()
methods from spatie/laravel-permission:
// Direct permissions
$user->getDirectPermissions() // Or $user->permissions;
// Permissions inherited from the user's roles
$user->getPermissionsViaRoles();
// All permissions which apply on the user (inherited and direct)
$user->getAllPermissions();
Another way to do it is as below:
RoleBooleanGroup::make('Roles'), PermissionBooleanGroup::make('Permissions')->resolveUsing(function ($permissions, $user) { $values = []; foreach ($user->getAllPermissions() as $item) { $values[$item->name] = true; }
return $values;
}),
This does not remove those permissions however, once the role is removed from the user
RoleBooleanGroup::make('Roles'),
PermissionBooleanGroup::make('Permissions')->resolveUsing(function ($permissions, $user) {
$values = [];
foreach ($user->getAllPermissions() as $item) {
$values[$item->name] = true;
}
return $values;
}),
Laravel Version: 6.7
Nova Version: 2.9.2
vyuldashev/nova-permission: 2.4.1
Question
How can I get the permissions attached to a role to be shown as selected on the User Details and Edit User screens?
In the first screenshot below an Admin role has 3 permissions attached (view accounts, invoices, and subscriptions).
The other two screenshots show User Details and Edit User screens for Test Account that has an Admin role attached. However, the Admin role permissions (view accounts, invoices, and subscriptions) are not shown as selected.