Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Models/DatabaseHost.php
7432 views
1
<?php
2
3
namespace Pterodactyl\Models;
4
5
use Illuminate\Database\Eloquent\Relations\HasMany;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
use Illuminate\Database\Eloquent\Factories\HasFactory;
8
9
/**
10
* @property int $id
11
* @property string $name
12
* @property string $host
13
* @property int $port
14
* @property string $username
15
* @property string $password
16
* @property int|null $max_databases
17
* @property int|null $node_id
18
* @property \Carbon\CarbonImmutable $created_at
19
* @property \Carbon\CarbonImmutable $updated_at
20
*/
21
class DatabaseHost extends Model
22
{
23
/** @use HasFactory<\Database\Factories\DatabaseHostFactory> */
24
use HasFactory;
25
26
/**
27
* The resource name for this model when it is transformed into an
28
* API representation using fractal.
29
*/
30
public const RESOURCE_NAME = 'database_host';
31
32
protected bool $immutableDates = true;
33
34
/**
35
* The table associated with the model.
36
*/
37
protected $table = 'database_hosts';
38
39
/**
40
* The attributes excluded from the model's JSON form.
41
*/
42
protected $hidden = ['password'];
43
44
/**
45
* Fields that are mass assignable.
46
*/
47
protected $fillable = [
48
'name', 'host', 'port', 'username', 'password', 'max_databases', 'node_id',
49
];
50
51
/**
52
* Cast values to correct type.
53
*/
54
protected $casts = [
55
'id' => 'integer',
56
'max_databases' => 'integer',
57
'node_id' => 'integer',
58
];
59
60
/**
61
* Validation rules to assign to this model.
62
*/
63
public static array $validationRules = [
64
'name' => 'required|string|max:191',
65
'host' => 'required|string',
66
'port' => 'required|numeric|between:1,65535',
67
'username' => 'required|string|max:32',
68
'password' => 'nullable|string',
69
'node_id' => 'sometimes|nullable|integer|exists:nodes,id',
70
];
71
72
/**
73
* Gets the node associated with a database host.
74
*/
75
public function node(): BelongsTo
76
{
77
return $this->belongsTo(Node::class);
78
}
79
80
/**
81
* Gets the databases associated with this host.
82
*/
83
public function databases(): HasMany
84
{
85
return $this->hasMany(Database::class);
86
}
87
}
88
89