Files

84 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2015-12-07 00:47:19 -05:00
<?php
2016-12-07 22:46:38 +00:00
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
2015-12-07 00:47:19 -05:00
namespace Pterodactyl\Models;
2026-10-05 18:10:18 -04:00
use Database\Factories\AllocationFactory;
use Illuminate\Database\Eloquent\Attributes\Guarded;
2026-10-12 01:13:53 -04:00
use Illuminate\Database\Eloquent\Attributes\UseEloquentBuilder;
2026-10-05 18:10:18 -04:00
use Illuminate\Database\Eloquent\Casts\Attribute;
2024-10-21 19:18:20 -06:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2026-10-05 18:10:18 -04:00
use Illuminate\Database\Eloquent\Relations\BelongsTo;
2026-10-12 01:13:53 -04:00
use Pterodactyl\Models\Builders\AllocationBuilder;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Traits\HasHashid;
2022-10-14 10:59:20 -06:00
2019-11-16 13:33:01 -08:00
/**
2026-10-11 22:55:07 -04:00
* @property-read Node $node
2019-11-16 13:33:01 -08:00
*/
2026-10-05 18:10:18 -04:00
#[Guarded(['id', 'created_at', 'updated_at'])]
2026-10-12 01:13:53 -04:00
#[UseEloquentBuilder(AllocationBuilder::class)]
class Allocation extends Model
2015-12-07 00:47:19 -05:00
{
2026-10-05 18:10:18 -04:00
/** @use HasFactory<AllocationFactory> */
2024-10-21 19:18:20 -06:00
use HasFactory;
2026-10-05 18:10:18 -04:00
use HasHashid;
public const string RESOURCE_NAME = 'allocation';
2015-12-07 00:47:19 -05:00
/**
2026-10-05 18:10:18 -04:00
* @return array<string, string>
2015-12-07 00:47:19 -05:00
*/
2026-10-05 18:10:18 -04:00
protected function casts(): array
{
return [
'node_id' => 'integer',
'port' => 'integer',
'server_id' => 'integer',
];
}
2015-12-07 00:47:19 -05:00
2026-10-05 18:10:18 -04:00
public function getRouteKeyName(): string
{
return $this->getKeyName();
}
public function toString(): string
{
return sprintf('%s:%s', $this->ip, $this->port);
}
2017-08-05 21:10:32 -05:00
/**
2026-10-05 18:10:18 -04:00
* @return BelongsTo<Server, $this>
2017-08-05 21:10:32 -05:00
*/
2026-10-05 18:10:18 -04:00
public function server(): BelongsTo
2022-05-22 14:10:01 -04:00
{
2026-10-05 18:10:18 -04:00
return $this->belongsTo(Server::class);
2022-05-22 14:10:01 -04:00
}
/**
2026-10-05 18:10:18 -04:00
* @return BelongsTo<Node, $this>
*/
2026-10-05 18:10:18 -04:00
public function node(): BelongsTo
{
2026-10-05 18:10:18 -04:00
return $this->belongsTo(Node::class);
}
2017-08-05 21:10:32 -05:00
/**
2026-10-05 18:10:18 -04:00
* @return Attribute<string, never>
2017-08-05 21:10:32 -05:00
*/
2026-10-05 18:10:18 -04:00
protected function alias(): Attribute
2017-08-05 21:10:32 -05:00
{
2026-10-05 18:10:18 -04:00
return Attribute::make(get: fn (): string => $this->ip_alias ?? $this->ip);
2017-08-05 21:10:32 -05:00
}
2017-08-05 21:10:32 -05:00
/**
2026-10-05 18:10:18 -04:00
* @return Attribute<bool, never>
2017-08-05 21:10:32 -05:00
*/
2026-10-05 18:10:18 -04:00
protected function hasAlias(): Attribute
2017-08-05 21:10:32 -05:00
{
2026-10-05 18:10:18 -04:00
return Attribute::make(get: fn (): bool => $this->ip_alias !== null);
2017-08-05 21:10:32 -05:00
}
2015-12-07 00:47:19 -05:00
}