Mutator for giving permissions.

@param  mixed  $permissions
@return array  $_permissions
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;
	}
18772
public static function formatPermissions(array $userPermissions): array
    {
        $userPermissions = self::format($userPermissions);

        foreach ($userPermissions as $key => $permission) {
            $userPermissions[$key] = self::$permissions[$key];
        }

        return $userPermissions;
    }
516195
protected function getStoredPermission($permissions)
    {
        if (is_string($permissions)) {
            return PermissionProxy::findByName($permissions, $this->getDefaultGuardName());
        }

        if (is_array($permissions)) {
            return PermissionProxy::whereIn('name', $permissions)
                ->whereIn('guard_name', $this->getGuardNames())
                ->get();
        }

        return $permissions;
    }
1136586
public function setPermissions(array $permissions)
    {
        if (!is_array($permissions) || empty($permissions)) {
            throw new InvalidArgumentException('You have to provide at least one permission!');
        }
        $this->permissions = $permissions;
    }
1140517
protected function canOne(array $permissions)
    {
        foreach ($permissions as $permission) {
            if ($this->hasPermission($permission)) {
                return true;
            }
        }

        return false;
    }
245795
public function hasPermissions($permissions)
    {
        if ($this->user() === null) {
            return null;
        }

        if (!is_array($permissions)) {
            $permissions = func_get_args();
        }

        // Count permissions because user need user to have all permissions passed as parameter
        return count(array_intersect($permissions, $this->permissions)) === count($permissions);
    }
1240880
public function getMultipleByName(array $permissions): array
    {
        if ($this->permissions === null) {
            $this->getAll();
        }

        $results = [];

        foreach ($permissions as $permission) {
            if (isset($this->names[$permission])) {
                $results[] = $this->permissions[$this->names[$permission]];
            }
        }

        return $results;
    }
834657
public function create($permissions = 0755)
    {
        Filesystem::checkNotExists($this->path);
        Filesystem::checkWritable(dirname($this->path));
        mkdir($this->path, $permissions, true);
    }
510393
public function filterByPermission($permissions)
    {
        $permissions = is_array($permissions) ? $permissions : func_get_args();

        foreach ($permissions as $permission) {
            if (!$this->auth->user()->can($permission)) {
                throw new PermissionDeniedException("You don't have permission to \"{$permission}\".");
            }
        }
    }
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);
        }
    }
670836
public static function check($permissions)
    {
        if (Schema::hasTable('laralum_permissions')) {
            foreach ($permissions as $permission) {
                if (!self::allCached()->contains('slug', $permission['slug'])) {
                    Cache::forget('laralum_permissions');
                    if (!self::allCached()->contains('slug', $permission['slug'])) {
                        Permission::create([
                            'name'        => $permission['name'],
                            'slug'        => $permission['slug'],
                            'description' => $permission['desc'],
                        ]);
                    }
                }
            }
        }
        session(['laralum_permissions::mandatory' => array_merge(static::mandatory(), $permissions)]);
    }
215045
public function syncPermissions($permissions)
    {
        $mappedPermissions = [];

        foreach ($permissions as $permission) {
            $mappedPermissions[] = Helper::getIdFor($permission, 'permission');
        }

        $changes = $this->permissions()->sync($mappedPermissions);
        $this->flushCache();
        $this->fireLaratrustEvent("permission.synced", [$this, $changes]);

        return $this;
    }
644001
private function cumulatePermissions(array $userPermission, array $permissions)
    {
        return $this->mapPermissions($userPermission, $permissions, function($permission1, $permission2) {
            return $permission1 || $permission2;
        });
    }
618231
protected function convertToPermissionModels($permissions): array
    {
        if ($permissions instanceof Collection) {
            $permissions = $permissions->all();
        }

        $permissions = array_wrap($permissions);

        return array_map(function ($permission) {
            if ($permission instanceof Permission) {
                return $permission;
            }

            return app(Permission::class)->findByName($permission, $this->getDefaultGuardName());
        }, $permissions);
    }
90361
public function canAll($permissions, &$failed = null)
    {
        $this->canAny($permissions, $failed);

        return $failed->isEmpty();
    }
1116211
public static function getPermissionIds($permissions)
    {
        foreach ($permissions as &$permission) {
            //determine if permission references element, get id if it does
            if (preg_match('/(:)/', $permission)) {
                $permissionParts = explode(":", $permission);
                $element = null;

                if (preg_match('/entries|entrydrafts/', $permissionParts[0])) {
                    $element = Craft::$app->sections->getSectionByHandle($permissionParts[1]);
                } elseif (preg_match('/volume/', $permissionParts[0])) {
                    $element = Craft::$app->volumes->getVolumeByHandle($permissionParts[1]);
                } elseif (preg_match('/categories/', $permissionParts[0])) {
                    $element = Craft::$app->categories->getGroupByHandle($permissionParts[1]);
                } elseif (preg_match('/globalset/', $permissionParts[0])) {
                    $element = Craft::$app->globals->getSetByHandle($permissionParts[1]);
                }

                if ($element != null) {
                    $permission = $permissionParts[0].':'. (MigrationManagerHelper::isVersion('3.1')  ? $element->uid : $element->id);
                }
            }
        }

        return $permissions;
    }
466024
public function mayOne($permissions, &$failed = null)
    {
        $permissions = is_array($permissions) ? collect($permissions) : $permissions;

        $failed = $permissions->reject(function ($permission) {
            return $this->may($permission);
        })->values();

        return $permissions->count() !== $failed->count();
    }