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\HasMany;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
|
|
|
|
2020-06-27 17:35:02 +00:00
|
|
|
/**
|
2021-01-28 04:52:11 +00:00
|
|
|
* @property int $id
|
|
|
|
* @property string $short
|
|
|
|
* @property string $long
|
|
|
|
* @property \Carbon\Carbon $created_at
|
|
|
|
* @property \Carbon\Carbon $updated_at
|
|
|
|
* @property \Pterodactyl\Models\Node[] $nodes
|
2020-06-27 17:35:02 +00:00
|
|
|
* @property \Pterodactyl\Models\Server[] $servers
|
|
|
|
*/
|
2020-04-04 06:22:35 +00:00
|
|
|
class Location 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 = 'location';
|
2018-01-26 03:26:06 +00:00
|
|
|
|
2015-12-07 05:47:19 +00:00
|
|
|
/**
|
|
|
|
* The table associated with the model.
|
|
|
|
*/
|
|
|
|
protected $table = 'locations';
|
|
|
|
|
2016-01-17 04:10:46 +00:00
|
|
|
/**
|
|
|
|
* Fields that are not mass assignable.
|
|
|
|
*/
|
|
|
|
protected $guarded = ['id', 'created_at', 'updated_at'];
|
2017-02-10 22:09:56 +00:00
|
|
|
|
2017-06-25 00:49:09 +00:00
|
|
|
/**
|
|
|
|
* Rules ensuring that the raw data stored in the database meets expectations.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public static array $validationRules = [
|
2019-09-05 05:19:57 +00:00
|
|
|
'short' => 'required|string|between:1,60|unique:locations,short',
|
2020-09-26 23:29:26 +00:00
|
|
|
'long' => 'string|nullable|between:1,191',
|
2017-06-15 04:53:24 +00:00
|
|
|
];
|
|
|
|
|
2022-05-22 18:10:01 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getRouteKeyName(): string
|
|
|
|
{
|
|
|
|
return $this->getKeyName();
|
|
|
|
}
|
|
|
|
|
2017-02-10 22:09:56 +00:00
|
|
|
/**
|
2018-05-13 14:50:56 +00:00
|
|
|
* Gets the nodes in a specified location.
|
2017-02-10 22:09:56 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function nodes(): HasMany
|
2017-02-10 22:09:56 +00:00
|
|
|
{
|
|
|
|
return $this->hasMany(Node::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the servers within a given location.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function servers(): HasManyThrough
|
2017-02-10 22:09:56 +00:00
|
|
|
{
|
|
|
|
return $this->hasManyThrough(Server::class, Node::class);
|
|
|
|
}
|
2015-12-07 05:47:19 +00:00
|
|
|
}
|