Completed model updates for Services

This commit is contained in:
Dane Everitt 2017-02-05 17:58:17 -05:00
parent 09d23deed6
commit 323f1d943f
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
26 changed files with 299 additions and 167 deletions

View file

@ -40,5 +40,38 @@ class Service extends Model
*
* @var array
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
protected $fillable = ['id', 'created_at', 'updated_at'];
/**
* Gets all service options associated with this service.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function options()
{
return $this->hasMany(ServiceOptions::class);
}
/**
* Returns all of the packs associated with a service, regardless of the service option.
*
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
*/
public function packs()
{
return $this->hasManyThrough(
'Pterodactyl\Models\ServicePack', 'Pterodactyl\Models\ServiceOptions',
'service_id', 'option_id'
);
}
/**
* Gets all servers associated with this service.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function servers()
{
return $this->hasMany(Server::class);
}
}

View file

@ -48,9 +48,29 @@ class ServiceOptions extends Model
* @var array
*/
protected $casts = [
'parent_service' => 'integer',
'service_id' => 'integer',
];
/**
* Gets service associated with a service option.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function service()
{
return $this->belongsTo(Service::class);
}
/**
* Gets all servers associated with this service option.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function servers()
{
return $this->hasMany(Server::class, 'option_id');
}
/**
* Gets all variables associated with this service.
*
@ -68,6 +88,6 @@ class ServiceOptions extends Model
*/
public function packs()
{
return $this->hasMany(ServicePack::class, 'option');
return $this->hasMany(ServicePack::class, 'option_id');
}
}

View file

@ -56,4 +56,14 @@ class ServicePack extends Model
'selectable' => 'boolean',
'visible' => 'boolean',
];
/**
* Gets option associated with a service pack.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function option()
{
return $this->belongsTo(ServiceOptions::class);
}
}

View file

@ -53,4 +53,9 @@ class ServiceVariables extends Model
'user_editable' => 'integer',
'required' => 'integer',
];
public function serverVariables()
{
return $this->hasMany(ServerVariables::class, 'variable_id');
}
}