2015-12-07 06:47:19 +01:00
|
|
|
<?php
|
2016-12-07 23:46:38 +01:00
|
|
|
|
2015-12-07 06:47:19 +01:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
2019-11-16 22:33:01 +01:00
|
|
|
/**
|
2021-01-23 21:33:34 +01: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 22:33:01 +01:00
|
|
|
* @property \Pterodactyl\Models\Server|null $server
|
2021-01-23 21:33:34 +01:00
|
|
|
* @property \Pterodactyl\Models\Node $node
|
2019-11-16 22:33:01 +01:00
|
|
|
*/
|
2020-04-04 08:22:35 +02:00
|
|
|
class Allocation extends Model
|
2015-12-07 06:47:19 +01:00
|
|
|
{
|
2018-01-26 04:26:06 +01:00
|
|
|
/**
|
|
|
|
* The resource name for this model when it is transformed into an
|
|
|
|
* API representation using fractal.
|
|
|
|
*/
|
2021-01-23 21:33:34 +01:00
|
|
|
public const RESOURCE_NAME = 'allocation';
|
2018-01-26 04:26:06 +01:00
|
|
|
|
2015-12-07 06:47:19 +01:00
|
|
|
/**
|
|
|
|
* The table associated with the model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $table = 'allocations';
|
|
|
|
|
2016-01-10 06:38:16 +01:00
|
|
|
/**
|
|
|
|
* Fields that are not mass assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $guarded = ['id', 'created_at', 'updated_at'];
|
|
|
|
|
2017-08-06 04:10:32 +02:00
|
|
|
/**
|
|
|
|
* Cast values to correct type.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'node_id' => 'integer',
|
|
|
|
'port' => 'integer',
|
|
|
|
'server_id' => 'integer',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2019-09-05 07:19:57 +02:00
|
|
|
public static $validationRules = [
|
|
|
|
'node_id' => 'required|exists:nodes,id',
|
|
|
|
'ip' => 'required|ip',
|
|
|
|
'port' => 'required|numeric|between:1024,65553',
|
2017-11-11 04:47:43 +01:00
|
|
|
'ip_alias' => 'nullable|string',
|
2017-08-06 04:10:32 +02:00
|
|
|
'server_id' => 'nullable|exists:servers,id',
|
2020-07-10 05:36:08 +02:00
|
|
|
'notes' => 'nullable|string|max:256',
|
2017-08-06 04:10:32 +02:00
|
|
|
];
|
2017-02-06 01:19:46 +01:00
|
|
|
|
2017-10-21 04:32:57 +02:00
|
|
|
/**
|
|
|
|
* Return a hashid encoded string to represent the ID of the allocation.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getHashidAttribute()
|
|
|
|
{
|
|
|
|
return app()->make('hashids')->encode($this->id);
|
|
|
|
}
|
|
|
|
|
2017-08-06 04:10:32 +02:00
|
|
|
/**
|
|
|
|
* Accessor to automatically provide the IP alias if defined.
|
|
|
|
*
|
2020-04-04 08:22:35 +02:00
|
|
|
* @param string|null $value
|
2021-01-23 21:33:34 +01:00
|
|
|
*
|
2017-08-06 04:10:32 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getAliasAttribute($value)
|
|
|
|
{
|
|
|
|
return (is_null($this->ip_alias)) ? $this->ip : $this->ip_alias;
|
|
|
|
}
|
2017-02-09 23:43:54 +01:00
|
|
|
|
2017-08-06 04:10:32 +02:00
|
|
|
/**
|
|
|
|
* Accessor to quickly determine if this allocation has an alias.
|
|
|
|
*
|
2020-04-04 08:22:35 +02:00
|
|
|
* @param string|null $value
|
2021-01-23 21:33:34 +01:00
|
|
|
*
|
2017-08-06 04:10:32 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getHasAliasAttribute($value)
|
|
|
|
{
|
2021-01-23 21:33:34 +01:00
|
|
|
return !is_null($this->ip_alias);
|
2017-08-06 04:10:32 +02:00
|
|
|
}
|
2017-02-18 01:59:40 +01:00
|
|
|
|
2017-08-06 04:10:32 +02:00
|
|
|
/**
|
|
|
|
* Gets information for the server associated with this allocation.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function server()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Server::class);
|
|
|
|
}
|
2018-01-11 06:19:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the Node model associated with this allocation.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function node()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Node::class);
|
|
|
|
}
|
2015-12-07 06:47:19 +01:00
|
|
|
}
|