Path: blob/1.0-develop/app/Repositories/Eloquent/LocationRepository.php
7460 views
<?php12namespace Pterodactyl\Repositories\Eloquent;34use Pterodactyl\Models\Location;5use Illuminate\Support\Collection;6use Illuminate\Database\Eloquent\ModelNotFoundException;7use Pterodactyl\Exceptions\Repository\RecordNotFoundException;8use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;910class LocationRepository extends EloquentRepository implements LocationRepositoryInterface11{12/**13* Return the model backing this repository.14*/15public function model(): string16{17return Location::class;18}1920/**21* Return locations with a count of nodes and servers attached to it.22*/23public function getAllWithDetails(): Collection24{25return $this->getBuilder()->withCount('nodes', 'servers')->get($this->getColumns());26}2728/**29* Return all the available locations with the nodes as a relationship.30*/31public function getAllWithNodes(): Collection32{33return $this->getBuilder()->with('nodes')->get($this->getColumns());34}3536/**37* Return all the nodes and their respective count of servers for a location.38*39* @throws RecordNotFoundException40*/41public function getWithNodes(int $id): Location42{43try {44return $this->getBuilder()->with('nodes.servers')->findOrFail($id, $this->getColumns());45} catch (ModelNotFoundException) {46throw new RecordNotFoundException();47}48}4950/**51* Return a location and the count of nodes in that location.52*53* @throws RecordNotFoundException54*/55public function getWithNodeCount(int $id): Location56{57try {58return $this->getBuilder()->withCount('nodes')->findOrFail($id, $this->getColumns());59} catch (ModelNotFoundException) {60throw new RecordNotFoundException();61}62}63}646566