Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Eloquent/NestRepository.php
7460 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Eloquent;
4
5
use Pterodactyl\Models\Nest;
6
use Illuminate\Database\Eloquent\Collection;
7
use Pterodactyl\Contracts\Repository\NestRepositoryInterface;
8
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
9
10
class NestRepository extends EloquentRepository implements NestRepositoryInterface
11
{
12
/**
13
* Return the model backing this repository.
14
*/
15
public function model(): string
16
{
17
return Nest::class;
18
}
19
20
/**
21
* Return a nest or all nests with their associated eggs and variables.
22
*
23
* @throws RecordNotFoundException
24
*/
25
public function getWithEggs(?int $id = null): Collection|Nest
26
{
27
$instance = $this->getBuilder()->with('eggs', 'eggs.variables');
28
29
if (!is_null($id)) {
30
$instance = $instance->find($id, $this->getColumns());
31
if (!$instance) {
32
throw new RecordNotFoundException();
33
}
34
35
return $instance;
36
}
37
38
return $instance->get($this->getColumns());
39
}
40
41
/**
42
* Return a nest or all nests and the count of eggs and servers for that nest.
43
*
44
* @throws RecordNotFoundException
45
*/
46
public function getWithCounts(?int $id = null): Collection|Nest
47
{
48
$instance = $this->getBuilder()->withCount(['eggs', 'servers']);
49
50
if (!is_null($id)) {
51
$instance = $instance->find($id, $this->getColumns());
52
if (!$instance) {
53
throw new RecordNotFoundException();
54
}
55
56
return $instance;
57
}
58
59
return $instance->get($this->getColumns());
60
}
61
62
/**
63
* Return a nest along with its associated eggs and the servers relation on those eggs.
64
*
65
* @throws RecordNotFoundException
66
*/
67
public function getWithEggServers(int $id): Nest
68
{
69
$instance = $this->getBuilder()->with('eggs.servers')->find($id, $this->getColumns());
70
if (!$instance) {
71
throw new RecordNotFoundException();
72
}
73
74
/* @var Nest $instance */
75
return $instance;
76
}
77
}
78
79