@param Ability $ability
@param array   $options

@return array
439
public function serialize(Ability $ability, array $options = [])
    {
        $serialized = [
            'id' => $ability->getUuid(),
            'name' => $ability->getName(),
            'minResourceCount' => $ability->getMinResourceCount(),
            'minEvaluatedResourceCount' => $ability->getMinEvaluatedResourceCount(),
        ];

        return $serialized;
    }
939703
protected function raw($ability, array $arguments)
    {
        if (is_null($user = $this->resolveUser())) {
            return false;
        }

        $result = $this->callBeforeCallbacks($user, $ability, $arguments);

        if (is_null($result)) {
            $result = $this->callAuthCallback($user, $ability, $arguments);
        }

        $this->callAfterCallbacks($user, $ability, $arguments, $result);

        return $result;
    }
587748
protected function parseAbilityAndArguments($ability, $arguments)
    {
        if (is_string($ability) && (strpos($ability, '\\') === false)) {
            return array($ability, $arguments);
        }

        list(,, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);

        return array($this->normalizeGuessedAbilityName($caller['function']), $ability);
    }
909799
public function check($abilities, $arguments = [])
    {
        return collect($abilities)->every(function ($ability) use ($arguments) {
            try {
                return (bool) $this->raw($ability, $arguments);
            } catch (AuthorizationException $e) {
                return false;
            }
        });
    }
429446
public function denies($ability, $arguments = [])
    {
        if (!is_array($arguments)) {
            $arguments = [ $arguments ];
        }

        array_unshift($arguments, $ability);
        return call_user_func_array([ $this->gatekeeper, 'denies'], $arguments);
    }
1101851
public function options($options = [])
    {
        if (empty($options)) {
            return $this->options;
        }

        $this->options = array_merge($this->options, $options);
    }
547312
public function dissociateAbilityFromResources(Ability $ability, array $nodes)
    {
        foreach ($nodes as $node) {
            $ability->removeResource($node);
        }
        $this->om->persist($ability);
        $this->om->flush();
    }
938969
protected function compileAbilityIdentifiers($ability, $model)
    {
        $identifiers = new BaseCollection(
            is_null($model)
                ? [$ability, '*-*', '*']
                : $this->compileModelAbilityIdentifiers($ability, $model)
        );

        return $identifiers->map(function ($identifier) {
            return strtolower($identifier);
        });
    }
648271
public function authorize($ability, $arguments = array())
    {
        list($ability, $arguments) = $this->parseAbilityAndArguments($ability, $arguments);

        $gate = App::make('Nova\Auth\Access\GateInterface');

        return $this->authorizeAtGate($gate, $ability, $arguments);
    }
499889
public function countByAbility(Ability $ability)
    {
        return $this->createQueryBuilder('ca')
            ->select('COUNT(ca)')
            ->where('ca.ability = :ability')
            ->setParameter(':ability', $ability)
            ->getQuery()
            ->getSingleScalarResult();
    }
1162780
public function any($abilities, $arguments = [])
    {
        return collect($abilities)->contains(function ($ability) use ($arguments) {
            return $this->check($ability, $arguments);
        });
    }
1083641
protected function getAbilityIdsFromArray($abilities, array $attributes)
    {
        $groups = Helpers::groupModelsAndIdentifiersByType($abilities);

        $keyName = Models::ability()->getKeyName();

        $groups['strings'] = $this->abilitiesByName($groups['strings'], $attributes)
                                  ->pluck($keyName)->all();

        $groups['models'] = Arr::pluck($groups['models'], $keyName);

        return Arr::collapse($groups);
    }
14661
public function prepareCapabilities(array $capabilities = []): array
    {
        if (empty($capabilities)) {
            return [];
        }

        $result = [];
        foreach ($capabilities as $capName => $checked) {
            $checked = (bool)$checked;
            if (!$checked) {
                continue;
            }

            $capEntity = $this->Capabilities->newEntity();
            $capEntity->name = $capName;
            $result[] = $capEntity;
        }

        return $result;
    }
409682
protected function syncAbilities($abilities, $options = ['forbidden' => false])
    {
        $abilityKeys = $this->getAbilityIds($abilities);
        $authority = $this->getAuthority();
        $relation = $authority->abilities();

        $this->newPivotQuery($relation)
             ->where('entity_type', $authority->getMorphClass())
             ->whereNotIn($this->getRelatedPivotKeyName($relation), $abilityKeys)
             ->where('forbidden', $options['forbidden'])
             ->delete();

        if ($options['forbidden']) {
            (new ForbidsAbilities($this->authority))->to($abilityKeys);
        } else {
            (new GivesAbilities($this->authority))->to($abilityKeys);
        }
    }
1107266
public function authorizePermissionResource($resource, array $options = [])
    {
        $permissions = $this->resourcePermissionMap();
        $collection  = new Collection;
        foreach ($permissions as $method => $ability) {
            $collection->push(new Fluent([
                'ability' => $ability,
                'method'  => $method,
            ]));
        }

        $collection->groupBy('ability')->each(function ($permission, $ability) use ($resource, $options) {
            $this->middleware("can:{$resource}.{$ability}")
                 ->only($permission->pluck('method')->toArray());
        });
    }
266328
public function abilities()
    {
        $relation = $this->morphToMany(
            Models::classname(Ability::class),
            'entity',
            Models::table('permissions')
        )->withPivot('forbidden', 'scope');

        return Models::scope()->applyToRelation($relation);
    }
457025
protected function getAssociatedAbilityIds($authority, array $abilityIds, $forbidden)
    {
        if (is_null($authority)) {
            return $this->getAbilityIdsAssociatedWithEveryone($abilityIds, $forbidden);
        }

        $relation = $authority->abilities();

        $table = Models::table('abilities');

        $relation->whereIn("{$table}.id", $abilityIds)
                 ->wherePivot('forbidden', '=', $forbidden);

        Models::scope()->applyToRelation($relation);

        return $relation->get(["{$table}.id"])->pluck('id')->all();
    }