2016-02-08 23:03:02 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pterodactyl - Panel
|
2017-01-24 22:57:08 +00:00
|
|
|
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
2016-02-08 23:03:02 +00:00
|
|
|
*
|
2017-09-26 02:43:01 +00:00
|
|
|
* This software is licensed under the terms of the MIT license.
|
|
|
|
* https://opensource.org/licenses/MIT
|
2016-02-08 23:03:02 +00:00
|
|
|
*/
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2016-02-08 23:03:02 +00:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
2017-07-15 16:52:34 +00:00
|
|
|
use Sofa\Eloquence\Eloquence;
|
|
|
|
use Sofa\Eloquence\Validable;
|
2016-02-08 23:03:02 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2017-08-12 20:29:01 +00:00
|
|
|
use Sofa\Eloquence\Contracts\CleansAttributes;
|
2017-07-22 18:55:30 +00:00
|
|
|
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
|
2016-02-08 23:03:02 +00:00
|
|
|
|
2017-08-12 20:29:01 +00:00
|
|
|
class DatabaseHost extends Model implements CleansAttributes, ValidableContract
|
2016-02-08 23:03:02 +00:00
|
|
|
{
|
2017-07-15 16:52:34 +00:00
|
|
|
use Eloquence, Validable;
|
2017-06-18 00:48:31 +00:00
|
|
|
|
2016-02-08 23:03:02 +00:00
|
|
|
/**
|
|
|
|
* The table associated with the model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-03-16 23:35:29 +00:00
|
|
|
protected $table = 'database_hosts';
|
2016-02-08 23:03:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The attributes excluded from the model's JSON form.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $hidden = ['password'];
|
|
|
|
|
|
|
|
/**
|
2017-03-16 23:35:29 +00:00
|
|
|
* Fields that are mass assignable.
|
2016-02-08 23:03:02 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-03-16 23:35:29 +00:00
|
|
|
protected $fillable = [
|
2017-07-22 18:55:30 +00:00
|
|
|
'name', 'host', 'port', 'username', 'password', 'max_databases', 'node_id',
|
2017-03-16 23:35:29 +00:00
|
|
|
];
|
2016-02-08 23:03:02 +00:00
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Cast values to correct type.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'id' => 'integer',
|
|
|
|
'max_databases' => 'integer',
|
|
|
|
'node_id' => 'integer',
|
|
|
|
];
|
2017-02-03 20:19:14 +00:00
|
|
|
|
2017-07-15 16:52:34 +00:00
|
|
|
/**
|
|
|
|
* Application validation rules.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $applicationRules = [
|
|
|
|
'name' => 'required',
|
|
|
|
'host' => 'required',
|
|
|
|
'port' => 'required',
|
|
|
|
'username' => 'required',
|
2017-11-25 19:45:47 +00:00
|
|
|
'node_id' => 'sometimes',
|
2017-07-15 16:52:34 +00:00
|
|
|
];
|
|
|
|
|
2017-08-05 22:26:30 +00:00
|
|
|
/**
|
|
|
|
* Validation rules to assign to this model.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-07-15 16:52:34 +00:00
|
|
|
protected static $dataIntegrityRules = [
|
|
|
|
'name' => 'string|max:255',
|
|
|
|
'host' => 'ip|unique:database_hosts,host',
|
|
|
|
'port' => 'numeric|between:1,65535',
|
|
|
|
'username' => 'string|max:32',
|
|
|
|
'password' => 'nullable|string',
|
2017-11-25 19:45:47 +00:00
|
|
|
'node_id' => 'nullable|integer|exists:nodes,id',
|
2017-06-18 00:48:31 +00:00
|
|
|
];
|
2017-04-14 03:19:01 +00:00
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Gets the node associated with a database host.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
public function node()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Node::class);
|
|
|
|
}
|
2017-02-09 22:43:54 +00:00
|
|
|
|
2017-03-19 23:36:50 +00:00
|
|
|
/**
|
|
|
|
* Gets the databases assocaited with this host.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
|
|
|
public function databases()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Database::class);
|
|
|
|
}
|
2016-02-08 23:03:02 +00:00
|
|
|
}
|