Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Repositories/Eloquent/MountRepository.php
7460 views
1
<?php
2
3
namespace Pterodactyl\Repositories\Eloquent;
4
5
use Pterodactyl\Models\Mount;
6
use Pterodactyl\Models\Server;
7
use Illuminate\Support\Collection;
8
use Illuminate\Database\Eloquent\ModelNotFoundException;
9
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
10
11
class MountRepository extends EloquentRepository
12
{
13
/**
14
* Return the model backing this repository.
15
*/
16
public function model(): string
17
{
18
return Mount::class;
19
}
20
21
/**
22
* Return mounts with a count of eggs, nodes, and servers attached to it.
23
*/
24
public function getAllWithDetails(): Collection
25
{
26
return $this->getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns());
27
}
28
29
/**
30
* Return all the mounts and their respective relations.
31
*
32
* @throws RecordNotFoundException
33
*/
34
public function getWithRelations(string $id): Mount
35
{
36
try {
37
return $this->getBuilder()->with('eggs', 'nodes')->findOrFail($id, $this->getColumns());
38
} catch (ModelNotFoundException $exception) {
39
throw new RecordNotFoundException();
40
}
41
}
42
43
/**
44
* Return mounts available to a server (ignoring if they are or are not mounted).
45
*/
46
public function getMountListForServer(Server $server): Collection
47
{
48
return $this->getBuilder()
49
->whereHas('eggs', function ($q) use ($server) {
50
$q->where('id', '=', $server->egg_id);
51
})
52
->whereHas('nodes', function ($q) use ($server) {
53
$q->where('id', '=', $server->node_id);
54
})
55
->get($this->getColumns());
56
}
57
}
58
59