2015-12-07 05:47:19 +00:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2015-12-07 05:47:19 +00:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
2019-11-16 21:33:01 +00:00
|
|
|
/**
|
2022-05-07 19:05:28 +00:00
|
|
|
* Pterodactyl\Models\Allocation.
|
|
|
|
*
|
2021-01-28 04:52:11 +00:00
|
|
|
* @property int $id
|
|
|
|
* @property int $node_id
|
|
|
|
* @property string $ip
|
|
|
|
* @property string|null $ip_alias
|
|
|
|
* @property int $port
|
|
|
|
* @property int|null $server_id
|
|
|
|
* @property string|null $notes
|
|
|
|
* @property \Carbon\Carbon|null $created_at
|
|
|
|
* @property \Carbon\Carbon|null $updated_at
|
|
|
|
* @property string $alias
|
|
|
|
* @property bool $has_alias
|
2019-11-16 21:33:01 +00:00
|
|
|
* @property \Pterodactyl\Models\Server|null $server
|
2021-01-28 04:52:11 +00:00
|
|
|
* @property \Pterodactyl\Models\Node $node
|
2022-05-07 19:05:28 +00:00
|
|
|
* @property string $hashid
|
|
|
|
*
|
|
|
|
* @method static \Database\Factories\AllocationFactory factory(...$parameters)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation newModelQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation newQuery()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation query()
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereCreatedAt($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereIp($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereIpAlias($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereNodeId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereNotes($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation wherePort($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereServerId($value)
|
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereUpdatedAt($value)
|
2022-10-14 16:59:20 +00:00
|
|
|
*
|
2022-05-07 19:05:28 +00:00
|
|
|
* @mixin \Eloquent
|
2019-11-16 21:33:01 +00:00
|
|
|
*/
|
2020-04-04 06:22:35 +00:00
|
|
|
class Allocation extends Model
|
2015-12-07 05:47:19 +00:00
|
|
|
{
|
2018-01-26 03:26:06 +00:00
|
|
|
/**
|
|
|
|
* The resource name for this model when it is transformed into an
|
|
|
|
* API representation using fractal.
|
|
|
|
*/
|
2021-01-23 20:33:34 +00:00
|
|
|
public const RESOURCE_NAME = 'allocation';
|
2018-01-26 03:26:06 +00:00
|
|
|
|
2015-12-07 05:47:19 +00:00
|
|
|
/**
|
|
|
|
* The table associated with the model.
|
|
|
|
*/
|
|
|
|
protected $table = 'allocations';
|
|
|
|
|
2016-01-10 05:38:16 +00:00
|
|
|
/**
|
|
|
|
* Fields that are not mass assignable.
|
|
|
|
*/
|
|
|
|
protected $guarded = ['id', 'created_at', 'updated_at'];
|
|
|
|
|
2017-08-06 02:10:32 +00:00
|
|
|
/**
|
|
|
|
* Cast values to correct type.
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'node_id' => 'integer',
|
|
|
|
'port' => 'integer',
|
|
|
|
'server_id' => 'integer',
|
|
|
|
];
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
public static array $validationRules = [
|
2019-09-05 05:19:57 +00:00
|
|
|
'node_id' => 'required|exists:nodes,id',
|
|
|
|
'ip' => 'required|ip',
|
2021-07-17 17:02:15 +00:00
|
|
|
'port' => 'required|numeric|between:1024,65535',
|
2017-11-11 03:47:43 +00:00
|
|
|
'ip_alias' => 'nullable|string',
|
2017-08-06 02:10:32 +00:00
|
|
|
'server_id' => 'nullable|exists:servers,id',
|
2020-07-10 03:36:08 +00:00
|
|
|
'notes' => 'nullable|string|max:256',
|
2017-08-06 02:10:32 +00:00
|
|
|
];
|
2017-02-06 00:19:46 +00:00
|
|
|
|
2022-05-22 18:10:01 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getRouteKeyName(): string
|
|
|
|
{
|
|
|
|
return $this->getKeyName();
|
|
|
|
}
|
|
|
|
|
2017-10-21 02:32:57 +00:00
|
|
|
/**
|
|
|
|
* Return a hashid encoded string to represent the ID of the allocation.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function getHashidAttribute(): string
|
2017-10-21 02:32:57 +00:00
|
|
|
{
|
|
|
|
return app()->make('hashids')->encode($this->id);
|
|
|
|
}
|
|
|
|
|
2017-08-06 02:10:32 +00:00
|
|
|
/**
|
|
|
|
* Accessor to automatically provide the IP alias if defined.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function getAliasAttribute(?string $value): string
|
2017-08-06 02:10:32 +00:00
|
|
|
{
|
|
|
|
return (is_null($this->ip_alias)) ? $this->ip : $this->ip_alias;
|
|
|
|
}
|
2017-02-09 22:43:54 +00:00
|
|
|
|
2017-08-06 02:10:32 +00:00
|
|
|
/**
|
|
|
|
* Accessor to quickly determine if this allocation has an alias.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function getHasAliasAttribute(?string $value): bool
|
2017-08-06 02:10:32 +00:00
|
|
|
{
|
2021-01-23 20:33:34 +00:00
|
|
|
return !is_null($this->ip_alias);
|
2017-08-06 02:10:32 +00:00
|
|
|
}
|
2017-02-18 00:59:40 +00:00
|
|
|
|
2022-05-29 23:26:28 +00:00
|
|
|
public function toString(): string
|
|
|
|
{
|
|
|
|
return sprintf('%s:%s', $this->ip, $this->port);
|
|
|
|
}
|
|
|
|
|
2017-08-06 02:10:32 +00:00
|
|
|
/**
|
|
|
|
* Gets information for the server associated with this allocation.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function server(): BelongsTo
|
2017-08-06 02:10:32 +00:00
|
|
|
{
|
|
|
|
return $this->belongsTo(Server::class);
|
|
|
|
}
|
2018-01-11 05:19:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the Node model associated with this allocation.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function node(): BelongsTo
|
2018-01-11 05:19:03 +00:00
|
|
|
{
|
|
|
|
return $this->belongsTo(Node::class);
|
|
|
|
}
|
2015-12-07 05:47:19 +00:00
|
|
|
}
|