API tweaks to return more relevant information on server listing

This commit is contained in:
Dane Everitt 2017-02-02 16:24:08 -05:00
parent 32c21baab0
commit 7f51e5df62
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 54 additions and 1 deletions

View file

@ -117,7 +117,10 @@ class ServerController extends BaseController
}
// Requested Daemon Stats
$server = $query->first();
$server = $query->with(
'allocations',
'pack'
)->first();
if ($request->input('daemon') === 'true') {
$node = Models\Node::findOrFail($server->node);
$client = Models\Node::guzzleRequest($node->id);

View file

@ -208,4 +208,54 @@ class Server extends Model
return [];
}
/**
* Gets all allocations associated with this server.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function allocations()
{
return $this->hasMany(Allocation::class, 'assigned_to');
}
/**
* Gets information for the pack associated with this server.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function pack()
{
return $this->hasOne(ServicePack::class, 'id', 'pack');
}
/**
* Gets information for the service associated with this server.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function service()
{
return $this->hasOne(Service::class, 'id', 'service');
}
/**
* Gets information for the service option associated with this server.
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function option()
{
return $this->hasOne(ServiceOptions::class, 'id', 'option');
}
/**
* Gets information for the service variables associated with this server.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function variables()
{
return $this->hasMany(ServerVariables::class);
}
}