<?php12namespace Pterodactyl\Models;34use Illuminate\Notifications\Notifiable;5use Illuminate\Database\Eloquent\Relations\HasMany;6use Illuminate\Database\Eloquent\Relations\BelongsTo;7use Illuminate\Database\Eloquent\Factories\HasFactory;89/**10* @property int $id11* @property int $user_id12* @property int $server_id13* @property array $permissions14* @property \Carbon\Carbon $created_at15* @property \Carbon\Carbon $updated_at16* @property User $user17* @property Server $server18*/19class Subuser extends Model20{21/** @use HasFactory<\Database\Factories\SubuserFactory> */22use HasFactory;23use Notifiable;2425/**26* The resource name for this model when it is transformed into an27* API representation using fractal.28*/29public const RESOURCE_NAME = 'server_subuser';3031/**32* The table associated with the model.33*/34protected $table = 'subusers';3536/**37* Fields that are not mass assignable.38*/39protected $guarded = ['id', 'created_at', 'updated_at'];4041/**42* Cast values to correct type.43*/44protected $casts = [45'user_id' => 'int',46'server_id' => 'int',47'permissions' => 'array',48];4950public static array $validationRules = [51'user_id' => 'required|numeric|exists:users,id',52'server_id' => 'required|numeric|exists:servers,id',53'permissions' => 'nullable|array',54'permissions.*' => 'string',55];5657/**58* Return a hashid encoded string to represent the ID of the subuser.59*/60public function getHashidAttribute(): string61{62return app()->make('hashids')->encode($this->id);63}6465/**66* Gets the server associated with a subuser.67*68* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Pterodactyl\Models\Server, $this>69*/70public function server(): BelongsTo71{72return $this->belongsTo(Server::class);73}7475/**76* Gets the user associated with a subuser.77*78* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Pterodactyl\Models\User, $this>79*/80public function user(): BelongsTo81{82return $this->belongsTo(User::class);83}8485/**86* Gets the permissions associated with a subuser.87*88* @return \Illuminate\Database\Eloquent\Relations\HasMany<\Pterodactyl\Models\Permission, $this>89*/90public function permissions(): HasMany91{92return $this->hasMany(Permission::class);93}94}959697