Path: blob/1.0-develop/app/Repositories/Eloquent/ApiKeyRepository.php
7459 views
<?php12namespace Pterodactyl\Repositories\Eloquent;34use Pterodactyl\Models\User;5use Pterodactyl\Models\ApiKey;6use Illuminate\Support\Collection;7use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;89class ApiKeyRepository extends EloquentRepository implements ApiKeyRepositoryInterface10{11/**12* Return the model backing this repository.13*/14public function model(): string15{16return ApiKey::class;17}1819/**20* Get all the account API keys that exist for a specific user.21*/22public function getAccountKeys(User $user): Collection23{24return $this->getBuilder()->where('user_id', $user->id)25->where('key_type', ApiKey::TYPE_ACCOUNT)26->get($this->getColumns());27}2829/**30* Get all the application API keys that exist for a specific user.31*/32public function getApplicationKeys(User $user): Collection33{34return $this->getBuilder()->where('user_id', $user->id)35->where('key_type', ApiKey::TYPE_APPLICATION)36->get($this->getColumns());37}3839/**40* Delete an account API key from the panel for a specific user.41*/42public function deleteAccountKey(User $user, string $identifier): int43{44return $this->getBuilder()->where('user_id', $user->id)45->where('key_type', ApiKey::TYPE_ACCOUNT)46->where('identifier', $identifier)47->delete();48}4950/**51* Delete an application API key from the panel for a specific user.52*/53public function deleteApplicationKey(User $user, string $identifier): int54{55return $this->getBuilder()->where('user_id', $user->id)56->where('key_type', ApiKey::TYPE_APPLICATION)57->where('identifier', $identifier)58->delete();59}60}616263