Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Models/Subuser.php
7432 views
1
<?php
2
3
namespace Pterodactyl\Models;
4
5
use Illuminate\Notifications\Notifiable;
6
use Illuminate\Database\Eloquent\Relations\HasMany;
7
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8
use Illuminate\Database\Eloquent\Factories\HasFactory;
9
10
/**
11
* @property int $id
12
* @property int $user_id
13
* @property int $server_id
14
* @property array $permissions
15
* @property \Carbon\Carbon $created_at
16
* @property \Carbon\Carbon $updated_at
17
* @property User $user
18
* @property Server $server
19
*/
20
class Subuser extends Model
21
{
22
/** @use HasFactory<\Database\Factories\SubuserFactory> */
23
use HasFactory;
24
use Notifiable;
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 = 'server_subuser';
31
32
/**
33
* The table associated with the model.
34
*/
35
protected $table = 'subusers';
36
37
/**
38
* Fields that are not mass assignable.
39
*/
40
protected $guarded = ['id', 'created_at', 'updated_at'];
41
42
/**
43
* Cast values to correct type.
44
*/
45
protected $casts = [
46
'user_id' => 'int',
47
'server_id' => 'int',
48
'permissions' => 'array',
49
];
50
51
public static array $validationRules = [
52
'user_id' => 'required|numeric|exists:users,id',
53
'server_id' => 'required|numeric|exists:servers,id',
54
'permissions' => 'nullable|array',
55
'permissions.*' => 'string',
56
];
57
58
/**
59
* Return a hashid encoded string to represent the ID of the subuser.
60
*/
61
public function getHashidAttribute(): string
62
{
63
return app()->make('hashids')->encode($this->id);
64
}
65
66
/**
67
* Gets the server associated with a subuser.
68
*/
69
public function server(): BelongsTo
70
{
71
return $this->belongsTo(Server::class);
72
}
73
74
/**
75
* Gets the user associated with a subuser.
76
*/
77
public function user(): BelongsTo
78
{
79
return $this->belongsTo(User::class);
80
}
81
82
/**
83
* Gets the permissions associated with a subuser.
84
*/
85
public function permissions(): HasMany
86
{
87
return $this->hasMany(Permission::class);
88
}
89
}
90
91