Path: blob/1.0-develop/app/Repositories/Eloquent/NestRepository.php
10287 views
<?php12namespace Pterodactyl\Repositories\Eloquent;34use Pterodactyl\Models\Nest;5use Illuminate\Database\Eloquent\Collection;6use Pterodactyl\Contracts\Repository\NestRepositoryInterface;7use Pterodactyl\Exceptions\Repository\RecordNotFoundException;89class NestRepository extends EloquentRepository implements NestRepositoryInterface10{11/**12* Return the model backing this repository.13*/14public function model(): string15{16return Nest::class;17}1819/**20* Return a nest or all nests with their associated eggs and variables.21*22* @return \Illuminate\Database\Eloquent\Collection<int, \Pterodactyl\Models\Nest>|\Pterodactyl\Models\Nest23*24* @throws RecordNotFoundException25*/26public function getWithEggs(?int $id = null): Collection|Nest27{28$instance = $this->getBuilder()->with('eggs', 'eggs.variables');2930if (!is_null($id)) {31$instance = $instance->find($id, $this->getColumns());32if (!$instance) {33throw new RecordNotFoundException();34}3536return $instance;37}3839return $instance->get($this->getColumns());40}4142/**43* Return a nest or all nests and the count of eggs and servers for that nest.44*45* @return \Illuminate\Database\Eloquent\Collection<int, \Pterodactyl\Models\Nest>|\Pterodactyl\Models\Nest46*47* @throws RecordNotFoundException48*/49public function getWithCounts(?int $id = null): Collection|Nest50{51$instance = $this->getBuilder()->withCount(['eggs', 'servers']);5253if (!is_null($id)) {54$instance = $instance->find($id, $this->getColumns());55if (!$instance) {56throw new RecordNotFoundException();57}5859return $instance;60}6162return $instance->get($this->getColumns());63}6465/**66* Return a nest along with its associated eggs and the servers relation on those eggs.67*68* @throws RecordNotFoundException69*/70public function getWithEggServers(int $id): Nest71{72$instance = $this->getBuilder()->with('eggs.servers')->find($id, $this->getColumns());73if (!$instance) {74throw new RecordNotFoundException();75}7677return $instance; // @phpstan-ignore return.type78}79}808182