2015-12-07 06:47:19 +01:00
|
|
|
<?php
|
2016-01-20 01:10:39 +01:00
|
|
|
/**
|
2016-01-20 22:05:16 +01:00
|
|
|
* Pterodactyl - Panel
|
2017-01-24 23:57:08 +01:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-01-20 01:10:39 +01:00
|
|
|
*
|
2017-09-26 04:43:01 +02:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2016-01-20 01:10:39 +01:00
|
|
|
*/
|
2016-12-07 23:46:38 +01:00
|
|
|
|
2015-12-07 06:47:19 +01:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
2017-08-06 04:10:32 +02:00
|
|
|
use Sofa\Eloquence\Eloquence;
|
|
|
|
use Sofa\Eloquence\Validable;
|
2015-12-07 06:47:19 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2017-08-12 22:29:01 +02:00
|
|
|
use Sofa\Eloquence\Contracts\CleansAttributes;
|
2017-08-06 04:10:32 +02:00
|
|
|
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
|
2015-12-07 06:47:19 +01:00
|
|
|
|
2017-08-12 22:29:01 +02:00
|
|
|
class Allocation extends Model implements CleansAttributes, ValidableContract
|
2015-12-07 06:47:19 +01:00
|
|
|
{
|
2017-08-06 04:10:32 +02:00
|
|
|
use Eloquence, Validable;
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
protected static $applicationRules = [
|
|
|
|
'node_id' => 'required',
|
|
|
|
'ip' => 'required',
|
|
|
|
'port' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $dataIntegrityRules = [
|
|
|
|
'node_id' => 'exists:nodes,id',
|
|
|
|
'ip' => 'ip',
|
|
|
|
'port' => 'numeric|between:1024,65553',
|
|
|
|
'alias' => 'string',
|
|
|
|
'server_id' => 'nullable|exists:servers,id',
|
|
|
|
];
|
2017-02-06 01:19:46 +01:00
|
|
|
|
2017-08-06 04:10:32 +02:00
|
|
|
/**
|
|
|
|
* Accessor to automatically provide the IP alias if defined.
|
|
|
|
*
|
2017-08-22 05:10:48 +02:00
|
|
|
* @param null|string $value
|
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.
|
|
|
|
*
|
2017-08-22 05:10:48 +02:00
|
|
|
* @param null|string $value
|
2017-08-06 04:10:32 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function getHasAliasAttribute($value)
|
|
|
|
{
|
|
|
|
return ! is_null($this->ip_alias);
|
|
|
|
}
|
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);
|
|
|
|
}
|
2015-12-07 06:47:19 +01:00
|
|
|
}
|