From 7f51e5df620d0bfecad1a116ee613e74ef9006ae Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 2 Feb 2017 16:24:08 -0500 Subject: [PATCH] API tweaks to return more relevant information on server listing --- app/Http/Controllers/API/ServerController.php | 5 +- app/Models/Server.php | 50 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/API/ServerController.php b/app/Http/Controllers/API/ServerController.php index b24cdac62..bc0d04a40 100755 --- a/app/Http/Controllers/API/ServerController.php +++ b/app/Http/Controllers/API/ServerController.php @@ -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); diff --git a/app/Models/Server.php b/app/Models/Server.php index 3a11603c2..a9f9bd087 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -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); + } }