Make sure to not sync root admin role (#1113)

This commit is contained in:
Boy132 2025-03-17 17:23:44 +01:00 committed by GitHub
parent f2f3ee548f
commit f563128237
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -122,6 +122,11 @@ class UserResource extends Resource
CheckboxList::make('roles') CheckboxList::make('roles')
->disableOptionWhen(fn (string $value): bool => $value == Role::getRootAdmin()->id) ->disableOptionWhen(fn (string $value): bool => $value == Role::getRootAdmin()->id)
->relationship('roles', 'name') ->relationship('roles', 'name')
->saveRelationshipsUsing(function (User $user, array $state) {
$roles = collect($state)->map(fn ($role) => Role::findById($role))->filter(fn ($role) => $role->id !== Role::getRootAdmin()->id);
$user->syncRoles($roles);
})
->dehydrated() ->dehydrated()
->label(trans('admin/user.admin_roles')) ->label(trans('admin/user.admin_roles'))
->columnSpanFull() ->columnSpanFull()