Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Models/Location.php
7432 views
1
<?php
2
3
namespace Pterodactyl\Models;
4
5
use Illuminate\Database\Eloquent\Relations\HasMany;
6
use Illuminate\Database\Eloquent\Factories\HasFactory;
7
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
8
9
/**
10
* @property int $id
11
* @property string $short
12
* @property string $long
13
* @property \Carbon\Carbon $created_at
14
* @property \Carbon\Carbon $updated_at
15
* @property \Pterodactyl\Models\Node[] $nodes
16
* @property \Pterodactyl\Models\Server[] $servers
17
*/
18
class Location extends Model
19
{
20
/** @use HasFactory<\Database\Factories\LocationFactory> */
21
use HasFactory;
22
23
/**
24
* The resource name for this model when it is transformed into an
25
* API representation using fractal.
26
*/
27
public const RESOURCE_NAME = 'location';
28
29
/**
30
* The table associated with the model.
31
*/
32
protected $table = 'locations';
33
34
/**
35
* Fields that are not mass assignable.
36
*/
37
protected $guarded = ['id', 'created_at', 'updated_at'];
38
39
/**
40
* Rules ensuring that the raw data stored in the database meets expectations.
41
*/
42
public static array $validationRules = [
43
'short' => 'required|string|between:1,60|unique:locations,short',
44
'long' => 'string|nullable|between:1,191',
45
];
46
47
public function getRouteKeyName(): string
48
{
49
return $this->getKeyName();
50
}
51
52
/**
53
* Gets the nodes in a specified location.
54
*/
55
public function nodes(): HasMany
56
{
57
return $this->hasMany(Node::class);
58
}
59
60
/**
61
* Gets the servers within a given location.
62
*/
63
public function servers(): HasManyThrough
64
{
65
return $this->hasManyThrough(Server::class, Node::class);
66
}
67
}
68
69