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