Services\UserGroupManager::deleteUserGroup PHP Method

deleteUserGroup() public method

Delete an existing user group
public deleteUserGroup ( $id ) : mixed | void
$id
return mixed | void
    public function deleteUserGroup($id)
    {
        try {
            // Find the group using the group id
            $group = Sentry::findGroupById($id);
            $users = Sentry::findAllUsersInGroup($group);
            if ($users->count() > 0) {
                throw new Exception('Some users are associated with the selected user group.
                First change the user group of those users or delete those users.');
            }
            // Delete the group
            $group->delete();
            $message = trans('success_messages.user_group_delete');
            return $message;
        } catch (GroupNotFoundException $e) {
            throw new Exception('Group was not found.');
        }
    }