Attach a collection of permissions to the group.

@param  \Illuminate\Database\Eloquent\Collection|array  $permissions
@param  bool                                            $reload

@return \Illuminate\Database\Eloquent\Collection|array
972005
public function attachPermissions($permissions, $reload = true)
    {
        event(new AttachingPermissionsToGroup($this, $permissions));
        $permissions = $this->permissions()->saveMany($permissions);
        event(new AttachedPermissionsToGroup($this, $permissions));

        $this->loadPermissions($reload);

        return $permissions;
    }
469379
public function createRepositoryPermissions($permissions)
    {
		$url = $this->service_url . '/permissions';
		$body = json_encode(array('permission' => $permissions));
		$permissions = $this->service->prepAndSend($url, array(201), 'POST', $body, true, 'application/collection+json', 'application/json');
        return self::batchDataToArray($permissions);
	}
1223112
public function attachUser($user, $reload = true)
    {
        if ($this->hasUser($user)) return;

        event(new AttachingUserToRole($this, $user));
        $this->users()->attach($user);
        event(new AttachedUserToRole($this, $user));

        $this->loadUsers($reload);
    }
1316896
public function detachAllRoles($reload = true)
    {
        event(new DetachingAllRolesFromPermission($this));
        $results = $this->roles()->detach();
        event(new DetachedAllRolesFromPermission($this, $results));

        $this->loadRoles($reload);

        return $results;
    }
666208
public function setPermissionsAttribute($permissions)
    {
        $module = lcfirst($this->attributes['name']);

        $roles = array();

        //prefix the permission with the module name ex: user.create
        foreach ($permissions as $key => $value)
        {
            $roles[] = $module . '.' . $value;
        }

        $this->attributes['permissions'] = ( ! empty($roles)) ? json_encode($roles) : '';
    }
1341081
protected function addPermissions(Collection $permissions)
    {
        foreach ($permissions as $permission) {
            $this->permissions[] = $permission->token;
        }
    }
849827
protected function toDotPermissions(array $permissions)
    {
        $data = [];
        //$permissions = $this->permissions->lists('slug', 'name');
        foreach ($permissions as $alias => $perm) {
            if ( ! is_array($perm) ) continue;
            foreach ($perm as $key => $value) {
                //if ( (bool) $value == false ) continue;
                $slug = $key . '.' . $alias;
                $data[$slug] = $value;
                //$data[] = $slug;
            }
        }

        return $data;
    }
11326
public function getPermissionsAttribute($permissions)
	{
		if ( ! $permissions)
		{
			return array();
		}

		if (is_array($permissions))
		{
			return $permissions;
		}

		if ( ! $_permissions = json_decode($permissions, true))
		{
			throw new \InvalidArgumentException("Cannot JSON decode permissions [$permissions].");
		}

		return $_permissions;
	}
707848
public function setPermissionsAttribute($permissions)
    {
        if (! ($permissions instanceof ChannelPermission)) {
            return;
        }

        list($allow, $deny) = $permissions->bitwise;
        $this->allow        = $allow;
        $this->deny         = $deny;

        $this->attributes['permissions'] = $permissions;
    }
931835
public function losePermissions($permissions): void
    {
        if (!is_array($permissions) && !$permissions instanceof Collection) {
            $permissions = func_get_args();
        }

        foreach ($permissions as $permission) {
            $permission = $this->resolvePermission($permission);

            $this->permissions()->detach($permission);
        }
    }
1140517
protected function canOne(array $permissions)
    {
        foreach ($permissions as $permission) {
            if ($this->hasPermission($permission)) {
                return true;
            }
        }

        return false;
    }
1093467
public function sanitizePermissionsValue($permissions, $revision)
    {
        if (is_array($permissions)) {
            $legacyOptions = ['print' => 4, 'modify' => 8, 'copy' => 16, 'annot-forms' => 32];
            foreach ($permissions as $key => $value) {
                if (isset($legacyOptions[$value])) {
                    $permissions[$key] = $legacyOptions[$value];
                } elseif (!is_int($value)) {
                    throw new \InvalidArgumentException(
                        sprintf('Invalid permission value: %s', $value)
                    );
                }
            }

            $permissions = array_sum($permissions);
        }

        $permissions = (int)$permissions;

        $allowed = self::PERM_PRINT
            | self::PERM_MODIFY
            | self::PERM_COPY
            | self::PERM_ANNOT;

        if ($revision > 2) {
            $allowed |= self::PERM_FILL_FORM
                | self::PERM_ACCESSIBILITY
                | self::PERM_ASSEMBLE
                | self::PERM_DIGITAL_PRINT;
        }

        if (($allowed & $permissions) !== $permissions) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Permission flags (%s) are not allowed for this security handler revision %s.',
                    $permissions,
                    $revision
                )
            );
        }

        $permissions = 61632 | 0xFFFF0000 | $permissions;
        if ($revision < 3) {
            // 3840 = bit 9 to 12 to 1 - we are < revision 3
            $permissions |= 3840;
        }

        // PDF integer are 32 bit integers. Ensure this.
        if (PHP_INT_SIZE === 4 || ($permissions) < (2147483647)) {
            return $permissions;
        }

        return ($permissions | (4294967295 << 32));
    }
562422
public function updatePermissions($permissions)
    {
        if ($this->isLink()) return;
        
        self::getDbConnection()->executeQuery('DELETE FROM users_groups_allow_cat WHERE catalog_id='.$this->id);
        if (is_array($permissions)) 
            foreach ($permissions as $pid => $groups)
                foreach($groups as $gid) if ($gid && $gid != GROUP_ADMIN)
                    self::getDbConnection()->executeQuery('INSERT INTO users_groups_allow_cat SET permission='.(int)$pid.', group_id='.(int)$gid.', catalog_id='.(int)$this->id);

    }
425877
public function setPermissionsAttribute(array $permissions)
	{
		// Merge permissions
		$permissions = array_merge($this->getPermissions(), $permissions);

		// Loop through and adjust permissions as needed
		foreach ($permissions as $permission => &$value)
		{
			// Lets make sure their is a valid permission value
			if ( ! in_array($value = (int) $value, $this->allowedPermissionsValues))
			{
				throw new \InvalidArgumentException("Invalid value [$value] for permission [$permission] given.");
			}

			// If the value is 0, delete it
			if ($value === 0)
			{
				unset($permissions[$permission]);
			}
		}

		$this->attributes['permissions'] = ( ! empty($permissions)) ? $permissions : '';
	}
727088
public function syncPermissions(array $permissions)
    {
        $permissionIds = [];
        foreach ($permissions as $name) {
            $permissionIds[] = app(Permission::class)->firstOrCreate(['name' => $name])->id;
        }
        $this->permissions()->sync($permissionIds);
    }
258916
public function givePermissionTo(...$permissions)
    {
        $permissions = collect($permissions)
            ->flatten()
            ->map(function ($permission) {
                return $this->getStoredPermission($permission);
            })
            ->each(function ($permission) {
                $this->ensureModelSharesGuard($permission);
            })
            ->all();

        $this->permissions()->saveMany($permissions);

        $this->forgetCachedPermissions();

        return $this;
    }
992537
public function attachPermissions($permissions = [], $team = null)
    {
        foreach ($permissions as $permission) {
            $this->attachPermission($permission, $team);
        }

        return $this;
    }