*/ use HasFactory; use HasHashid; public const string RESOURCE_NAME = 'allocation'; /** * @return array */ protected function casts(): array { return [ 'node_id' => 'integer', 'port' => 'integer', 'server_id' => 'integer', ]; } public function getRouteKeyName(): string { return $this->getKeyName(); } public function toString(): string { return sprintf('%s:%s', $this->ip, $this->port); } /** * @return BelongsTo */ public function server(): BelongsTo { return $this->belongsTo(Server::class); } /** * @return BelongsTo */ public function node(): BelongsTo { return $this->belongsTo(Node::class); } /** * @return Attribute */ protected function alias(): Attribute { return Attribute::make(get: fn (): string => $this->ip_alias ?? $this->ip); } /** * @return Attribute */ protected function hasAlias(): Attribute { return Attribute::make(get: fn (): bool => $this->ip_alias !== null); } }