Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Eloquent/LocationRepository.php
7460 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Eloquent;
4
5
use Pterodactyl\Models\Location;
6
use Illuminate\Support\Collection;
7
use Illuminate\Database\Eloquent\ModelNotFoundException;
8
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
9
use Pterodactyl\Contracts\Repository\LocationRepositoryInterface;
10
11
class LocationRepository extends EloquentRepository implements LocationRepositoryInterface
12
{
13
/**
14
* Return the model backing this repository.
15
*/
16
public function model(): string
17
{
18
return Location::class;
19
}
20
21
/**
22
* Return locations with a count of nodes and servers attached to it.
23
*/
24
public function getAllWithDetails(): Collection
25
{
26
return $this->getBuilder()->withCount('nodes', 'servers')->get($this->getColumns());
27
}
28
29
/**
30
* Return all the available locations with the nodes as a relationship.
31
*/
32
public function getAllWithNodes(): Collection
33
{
34
return $this->getBuilder()->with('nodes')->get($this->getColumns());
35
}
36
37
/**
38
* Return all the nodes and their respective count of servers for a location.
39
*
40
* @throws RecordNotFoundException
41
*/
42
public function getWithNodes(int $id): Location
43
{
44
try {
45
return $this->getBuilder()->with('nodes.servers')->findOrFail($id, $this->getColumns());
46
} catch (ModelNotFoundException) {
47
throw new RecordNotFoundException();
48
}
49
}
50
51
/**
52
* Return a location and the count of nodes in that location.
53
*
54
* @throws RecordNotFoundException
55
*/
56
public function getWithNodeCount(int $id): Location
57
{
58
try {
59
return $this->getBuilder()->withCount('nodes')->findOrFail($id, $this->getColumns());
60
} catch (ModelNotFoundException) {
61
throw new RecordNotFoundException();
62
}
63
}
64
}
65
66