Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Eloquent/ApiKeyRepository.php
14042 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Eloquent;
4
5
use Pterodactyl\Models\User;
6
use Pterodactyl\Models\ApiKey;
7
use Illuminate\Support\Collection;
8
use Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface;
9
10
class ApiKeyRepository extends EloquentRepository implements ApiKeyRepositoryInterface
11
{
12
/**
13
* Return the model backing this repository.
14
*/
15
public function model(): string
16
{
17
return ApiKey::class;
18
}
19
20
/**
21
* Get all the account API keys that exist for a specific user.
22
*/
23
public function getAccountKeys(User $user): Collection
24
{
25
return $this->getBuilder()->where('user_id', $user->id)
26
->where('key_type', ApiKey::TYPE_ACCOUNT)
27
->get($this->getColumns());
28
}
29
30
/**
31
* Delete an account API key from the panel for a specific user.
32
*/
33
public function deleteAccountKey(User $user, string $identifier): int
34
{
35
return $this->getBuilder()->where('user_id', $user->id)
36
->where('key_type', ApiKey::TYPE_ACCOUNT)
37
->where('identifier', $identifier)
38
->delete();
39
}
40
}
41
42