relationLoaded('server') || $refresh) { $key->load('server'); } if (! $key->relationLoaded('user') || $refresh) { $key->load('user'); } return $key; } /** * Return a daemon key with the associated server relation attached. * * @param string $key * @return \Pterodactyl\Models\DaemonKey * * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function getKeyWithServer(string $key): DaemonKey { Assert::notEmpty($key, 'Expected non-empty string as first argument passed to ' . __METHOD__); try { return $this->getBuilder()->with('server')->where('secret', '=', $key)->firstOrFail($this->getColumns()); } catch (ModelNotFoundException $exception) { throw new RecordNotFoundException; } } /** * Get all of the keys for a specific user including the information needed * from their server relation for revocation on the daemon. * * @param \Pterodactyl\Models\User $user * @return \Illuminate\Support\Collection */ public function getKeysForRevocation(User $user): Collection { return $this->getBuilder()->with('node')->where('user_id', $user->id)->get($this->getColumns()); } /** * Delete an array of daemon keys from the database. Used primarily in * conjunction with getKeysForRevocation. * * @param array $ids * @return bool|int */ public function deleteKeys(array $ids) { return $this->getBuilder()->whereIn('id', $ids)->delete(); } }