From d6bd7e7a2ec0fdd54ac3e8684e74198f707358b8 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 26 Jan 2016 22:17:51 -0500 Subject: [PATCH] Fix casts on models; closes #49 --- app/Models/APIPermission.php | 9 +++++++++ app/Models/Allocation.php | 11 +++++++++++ app/Models/Node.php | 14 ++++++++++++++ app/Models/Permission.php | 10 ++++++++++ app/Models/Server.php | 21 +++++++++++++++++++++ app/Models/ServerVariables.php | 10 ++++++++++ app/Models/ServiceOptions.php | 9 +++++++++ app/Models/ServiceVariables.php | 12 ++++++++++++ app/Models/Subuser.php | 10 ++++++++++ app/Models/User.php | 10 ++++++++++ 10 files changed, 116 insertions(+) diff --git a/app/Models/APIPermission.php b/app/Models/APIPermission.php index 2d5b1c96c..99c564b2a 100644 --- a/app/Models/APIPermission.php +++ b/app/Models/APIPermission.php @@ -42,6 +42,15 @@ class APIPermission extends Model */ protected $guarded = ['id']; + /** + * Cast values to correct type. + * + * @var array + */ + protected $casts = [ + 'key_id' => 'integer', + ]; + /** * Disable timestamps for this table. * diff --git a/app/Models/Allocation.php b/app/Models/Allocation.php index 77b87c3d5..2eeff851d 100644 --- a/app/Models/Allocation.php +++ b/app/Models/Allocation.php @@ -42,4 +42,15 @@ class Allocation extends Model */ protected $guarded = ['id', 'created_at', 'updated_at']; + /** + * Cast values to correct type. + * + * @var array + */ + protected $casts = [ + 'node' => 'integer', + 'port' => 'integer', + 'assigned_to' => 'integer', + ]; + } diff --git a/app/Models/Node.php b/app/Models/Node.php index 28e30662a..61688da70 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -43,6 +43,20 @@ class Node extends Model */ protected $hidden = ['daemonSecret']; + /** + * Cast values to correct type. + * + * @var array + */ + protected $casts = [ + 'public' => 'integer', + 'location' => 'integer', + 'memory' => 'integer', + 'disk' => 'integer', + 'daemonListen' => 'integer', + 'daemonSFTP' => 'integer', + ]; + /** * Fields that are not mass assignable. * diff --git a/app/Models/Permission.php b/app/Models/Permission.php index 9322b0f8a..5a59d579d 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -42,6 +42,16 @@ class Permission extends Model */ protected $guarded = ['id', 'created_at', 'updated_at']; + /** + * Cast values to correct type. + * + * @var array + */ + protected $casts = [ + 'user_id' => 'integer', + 'server_id' => 'integer', + ]; + public function scopePermission($query, $permission) { return $query->where('permission', $permission); diff --git a/app/Models/Server.php b/app/Models/Server.php index e13cae2ff..4fa860f15 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -52,6 +52,27 @@ class Server extends Model */ protected $guarded = ['id', 'installed', 'created_at', 'updated_at']; + /** + * Cast values to correct type. + * + * @var array + */ + protected $casts = [ + 'node' => 'integer', + 'active' => 'integer', + 'owner' => 'integer', + 'memory' => 'integer', + 'swap' => 'integer', + 'disk' => 'integer', + 'io' => 'integer', + 'cpu' => 'integer', + 'oom_disabled' => 'integer', + 'port' => 'integer', + 'service' => 'integer', + 'option' => 'integer', + 'installed' => 'integer', + ]; + /** * @var array */ diff --git a/app/Models/ServerVariables.php b/app/Models/ServerVariables.php index 822a34858..d5d062489 100644 --- a/app/Models/ServerVariables.php +++ b/app/Models/ServerVariables.php @@ -42,4 +42,14 @@ class ServerVariables extends Model */ protected $guarded = ['id', 'created_at', 'updated_at']; + /** + * Cast values to correct type. + * + * @var array + */ + protected $casts = [ + 'server_id' => 'integer', + 'variable_id' => 'integer', + ]; + } diff --git a/app/Models/ServiceOptions.php b/app/Models/ServiceOptions.php index 3d6c89ea4..abe0a0dd2 100644 --- a/app/Models/ServiceOptions.php +++ b/app/Models/ServiceOptions.php @@ -35,4 +35,13 @@ class ServiceOptions extends Model */ protected $table = 'service_options'; + /** + * Cast values to correct type. + * + * @var array + */ + protected $casts = [ + 'parent_service' => 'integer', + ]; + } diff --git a/app/Models/ServiceVariables.php b/app/Models/ServiceVariables.php index a73db87c2..94399c8a4 100644 --- a/app/Models/ServiceVariables.php +++ b/app/Models/ServiceVariables.php @@ -35,4 +35,16 @@ class ServiceVariables extends Model */ protected $table = 'service_variables'; + /** + * Cast values to correct type. + * + * @var array + */ + protected $casts = [ + 'option_id' => 'integer', + 'user_viewable' => 'integer', + 'user_editable' => 'integer', + 'required' => 'integer', + ]; + } diff --git a/app/Models/Subuser.php b/app/Models/Subuser.php index 9a2d71760..5c22adfb7 100644 --- a/app/Models/Subuser.php +++ b/app/Models/Subuser.php @@ -50,6 +50,16 @@ class Subuser extends Model */ protected $guarded = ['id', 'created_at', 'updated_at']; + /** + * Cast values to correct type. + * + * @var array + */ + protected $casts = [ + 'user_id' => 'integer', + 'server_id' => 'integer', + ]; + /** * @var mixed */ diff --git a/app/Models/User.php b/app/Models/User.php index 1bef85b47..2a1f635e2 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -57,6 +57,16 @@ class User extends Model implements AuthenticatableContract, */ protected $guarded = ['id', 'remeber_token', 'created_at', 'updated_at']; + /** + * Cast values to correct type. + * + * @var array + */ + protected $casts = [ + 'root_admin' => 'integer', + 'use_totp' => 'integer', + ]; + /** * The attributes excluded from the model's JSON form. *