<?php12namespace Pterodactyl\Models;34use Illuminate\Database\Eloquent\Relations\BelongsTo;5use Illuminate\Database\Eloquent\Factories\HasFactory;67/**8* Pterodactyl\Models\Allocation.9*10* @property int $id11* @property int $node_id12* @property string $ip13* @property string|null $ip_alias14* @property int $port15* @property int|null $server_id16* @property string|null $notes17* @property \Carbon\Carbon|null $created_at18* @property \Carbon\Carbon|null $updated_at19* @property string $alias20* @property bool $has_alias21* @property Server|null $server22* @property Node $node23* @property string $hashid24*25* @method static \Database\Factories\AllocationFactory factory(...$parameters)26* @method static \Illuminate\Database\Eloquent\Builder|Allocation newModelQuery()27* @method static \Illuminate\Database\Eloquent\Builder|Allocation newQuery()28* @method static \Illuminate\Database\Eloquent\Builder|Allocation query()29* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereCreatedAt($value)30* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereId($value)31* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereIp($value)32* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereIpAlias($value)33* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereNodeId($value)34* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereNotes($value)35* @method static \Illuminate\Database\Eloquent\Builder|Allocation wherePort($value)36* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereServerId($value)37* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereUpdatedAt($value)38*39* @mixin \Eloquent40*/41class Allocation extends Model42{43/** @use HasFactory<\Database\Factories\AllocationFactory> */44use HasFactory;4546/**47* The resource name for this model when it is transformed into an48* API representation using fractal.49*/50public const RESOURCE_NAME = 'allocation';5152/**53* The table associated with the model.54*/55protected $table = 'allocations';5657/**58* Fields that are not mass assignable.59*/60protected $guarded = ['id', 'created_at', 'updated_at'];6162/**63* Cast values to correct type.64*/65protected $casts = [66'node_id' => 'integer',67'port' => 'integer',68'server_id' => 'integer',69];7071public static array $validationRules = [72'node_id' => 'required|exists:nodes,id',73'ip' => 'required|ip',74'port' => 'required|numeric|between:1024,65535',75'ip_alias' => 'nullable|string',76'server_id' => 'nullable|exists:servers,id',77'notes' => 'nullable|string|max:256',78];7980public function getRouteKeyName(): string81{82return $this->getKeyName();83}8485/**86* Return a hashid encoded string to represent the ID of the allocation.87*/88public function getHashidAttribute(): string89{90return app()->make('hashids')->encode($this->id);91}9293/**94* Accessor to automatically provide the IP alias if defined.95*/96public function getAliasAttribute(?string $value): string97{98return (is_null($this->ip_alias)) ? $this->ip : $this->ip_alias;99}100101/**102* Accessor to quickly determine if this allocation has an alias.103*/104public function getHasAliasAttribute(?string $value): bool105{106return !is_null($this->ip_alias);107}108109public function toString(): string110{111return sprintf('%s:%s', $this->ip, $this->port);112}113114/**115* Gets information for the server associated with this allocation.116*/117public function server(): BelongsTo118{119return $this->belongsTo(Server::class);120}121122/**123* Return the Node model associated with this allocation.124*/125public function node(): BelongsTo126{127return $this->belongsTo(Node::class);128}129}130131132