Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Models/ServerTransfer.php
7432 views
1
<?php
2
3
namespace Pterodactyl\Models;
4
5
use Illuminate\Database\Eloquent\Relations\HasOne;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
8
/**
9
* @property int $id
10
* @property int $server_id
11
* @property int $old_node
12
* @property int $new_node
13
* @property int $old_allocation
14
* @property int $new_allocation
15
* @property array|null $old_additional_allocations
16
* @property array|null $new_additional_allocations
17
* @property bool|null $successful
18
* @property bool $archived
19
* @property \Carbon\Carbon $created_at
20
* @property \Carbon\Carbon $updated_at
21
* @property Server $server
22
* @property Node $oldNode
23
* @property Node $newNode
24
*/
25
class ServerTransfer extends Model
26
{
27
/**
28
* The resource name for this model when it is transformed into an
29
* API representation using fractal.
30
*/
31
public const RESOURCE_NAME = 'server_transfer';
32
33
/**
34
* The table associated with the model.
35
*/
36
protected $table = 'server_transfers';
37
38
/**
39
* Fields that are not mass assignable.
40
*/
41
protected $guarded = ['id', 'created_at', 'updated_at'];
42
43
/**
44
* Cast values to correct type.
45
*/
46
protected $casts = [
47
'server_id' => 'int',
48
'old_node' => 'int',
49
'new_node' => 'int',
50
'old_allocation' => 'int',
51
'new_allocation' => 'int',
52
'old_additional_allocations' => 'array',
53
'new_additional_allocations' => 'array',
54
'successful' => 'bool',
55
'archived' => 'bool',
56
];
57
58
public static array $validationRules = [
59
'server_id' => 'required|numeric|exists:servers,id',
60
'old_node' => 'required|numeric',
61
'new_node' => 'required|numeric',
62
'old_allocation' => 'required|numeric',
63
'new_allocation' => 'required|numeric',
64
'old_additional_allocations' => 'nullable|array',
65
'old_additional_allocations.*' => 'numeric',
66
'new_additional_allocations' => 'nullable|array',
67
'new_additional_allocations.*' => 'numeric',
68
'successful' => 'sometimes|nullable|boolean',
69
];
70
71
/**
72
* Gets the server associated with a server transfer.
73
*/
74
public function server(): BelongsTo
75
{
76
return $this->belongsTo(Server::class);
77
}
78
79
/**
80
* Gets the source node associated with a server transfer.
81
*/
82
public function oldNode(): HasOne
83
{
84
return $this->hasOne(Node::class, 'id', 'old_node');
85
}
86
87
/**
88
* Gets the target node associated with a server transfer.
89
*/
90
public function newNode(): HasOne
91
{
92
return $this->hasOne(Node::class, 'id', 'new_node');
93
}
94
}
95
96