forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMountRepository.php
More file actions
57 lines (51 loc) · 1.62 KB
/
MountRepository.php
File metadata and controls
57 lines (51 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Pterodactyl\Repositories\Eloquent;
use Pterodactyl\Models\Mount;
use Pterodactyl\Models\Server;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
class MountRepository extends EloquentRepository
{
/**
* Return the model backing this repository.
*/
public function model(): string
{
return Mount::class;
}
/**
* Return mounts with a count of eggs, nodes, and servers attached to it.
*/
public function getAllWithDetails(): Collection
{
return $this->getBuilder()->withCount('eggs', 'nodes')->get($this->getColumns());
}
/**
* Return all the mounts and their respective relations.
*
* @throws RecordNotFoundException
*/
public function getWithRelations(string $id): Mount
{
try {
return $this->getBuilder()->with('eggs', 'nodes')->findOrFail($id, $this->getColumns());
} catch (ModelNotFoundException $exception) {
throw new RecordNotFoundException();
}
}
/**
* Return mounts available to a server (ignoring if they are or are not mounted).
*/
public function getMountListForServer(Server $server): Collection
{
return $this->getBuilder()
->whereHas('eggs', function ($q) use ($server) {
$q->where('id', '=', $server->egg_id);
})
->whereHas('nodes', function ($q) use ($server) {
$q->where('id', '=', $server->node_id);
})
->get($this->getColumns());
}
}