Skip to content

A free open source IT asset/license management system

Added type casting and a few more validation rules

snipefa5134603f8d
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index be1f1a6fc0..f0bdf4321c 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -76,6 +76,14 @@ class Asset extends Depreciable
];
+ protected $casts = [
+ 'model_id' => 'integer',
+ 'status_id' => 'integer',
+ 'company_id' => 'integer',
+ 'location_id' => 'integer',
+ 'rtd_company_id' => 'integer',
+ 'supplier_id' => 'integer',
+ ];
protected $rules = [
'name' => 'max:255|nullable',
@@ -86,13 +94,15 @@ class Asset extends Depreciable
'physical' => 'numeric|max:1|nullable',
'checkout_date' => 'date|max:10|min:10|nullable',
'checkin_date' => 'date|max:10|min:10|nullable',
- 'supplier_id' => 'numeric|nullable',
+ 'supplier_id' => 'exists:suppliers,id|numeric|nullable',
+ 'location_id' => 'exists:locations,id|nullable',
+ 'rtd_location_id' => 'exists:locations,id|nullable',
'asset_tag' => 'required|min:1|max:255|unique_undeleted',
'status' => 'integer',
'serial' => 'unique_serial|nullable',
'purchase_cost' => 'numeric|nullable',
- 'next_audit_date' => 'date|nullable',
- 'last_audit_date' => 'date|nullable',
+ 'next_audit_date' => 'date|nullable',
+ 'last_audit_date' => 'date|nullable',
];
/**
diff --git a/app/Models/AssetModel.php b/app/Models/AssetModel.php
index f32ac0d414..1bb7902fda 100755
--- a/app/Models/AssetModel.php
+++ b/app/Models/AssetModel.php
@@ -24,11 +24,11 @@ class AssetModel extends SnipeModel
// Declare the rules for the model validation
protected $rules = array(
- 'name' => 'required|min:1|max:255',
+ 'name' => 'required|min:1|max:255',
'model_number' => 'max:255|nullable',
'category_id' => 'required|integer|exists:categories,id',
'manufacturer_id' => 'required|integer|exists:manufacturers,id',
- 'eol' => 'integer:min:0|max:240|nullable',
+ 'eol' => 'integer:min:0|max:240|nullable',
);
/**
diff --git a/app/Models/Category.php b/app/Models/Category.php
index b95ec6cf9e..b42463addd 100755
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -24,6 +24,12 @@ class Category extends SnipeModel
protected $table = 'categories';
protected $hidden = ['user_id','deleted_at'];
+
+ protected $casts = [
+ 'user_id' => 'integer',
+ ];
+
+
/**
* Category validation rules
*/
diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php
index 701b395162..14de8c6ebb 100644
--- a/app/Models/Consumable.php
+++ b/app/Models/Consumable.php
@@ -20,10 +20,15 @@ class Consumable extends SnipeModel
protected $dates = ['deleted_at', 'purchase_date'];
protected $table = 'consumables';
protected $casts = [
- 'requestable' => 'boolean'
+ 'requestable' => 'boolean',
+ 'category_id' => 'integer',
+ 'company_id' => 'integer',
+ 'qty' => 'integer',
+ 'min_amt' => 'integer',
];
+
/**
* Category validation rules
*/
diff --git a/app/Models/Department.php b/app/Models/Department.php
index eecf5712cd..96aa4dd860 100644
--- a/app/Models/Department.php
+++ b/app/Models/Department.php
@@ -19,6 +19,12 @@ class Department extends SnipeModel
use ValidatingTrait, UniqueUndeletedTrait;
+ protected $casts = [
+ 'manager_id' => 'integer',
+ 'location_id' => 'integer',
+ 'company_id' => 'integer',
+ ];
+
protected $rules = [
'name' => 'required|max:255',
'location_id' => 'numeric|nullable',
diff --git a/app/Models/License.php b/app/Models/License.php
index bc3894406e..649eb063f5 100755
--- a/app/Models/License.php
+++ b/app/Models/License.php
@@ -36,6 +36,13 @@ class License extends Depreciable
protected $guarded = 'id';
protected $table = 'licenses';
+
+ protected $casts = [
+ 'seats' => 'integer',
+ 'category_id' => 'integer',
+ 'company_id' => 'integer',
+ ];
+
protected $rules = array(
'name' => 'required|string|min:3|max:255',
'seats' => 'required|min:1|max:999|integer',
diff --git a/app/Models/Location.php b/app/Models/Location.php
index a99433ed96..3b6f862e52 100755
--- a/app/Models/Location.php
+++ b/app/Models/Location.php
@@ -27,9 +27,14 @@ class Location extends SnipeModel
'address2' => 'max:80|nullable',
'zip' => 'min:3|max:10|nullable',
'manager_id' => 'exists:users,id|nullable',
- 'parent_id' => 'nullable|different:id',
+ 'parent_id' => 'nullable|exists:locations,id|different:id',
);
+ protected $casts = [
+ 'parent_id' => 'integer',
+ 'manager_id' => 'integer',
+ ];
+
/**
* Whether the model should inject it's identifier to the unique
* validation rules before attempting validation. If this property
diff --git a/app/Models/User.php b/app/Models/User.php
index 27c8b6ffeb..109ad4f92d 100755
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -55,7 +55,10 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
];
protected $casts = [
- 'activated' => 'boolean',
+ 'activated' => 'boolean',
+ 'manager_id' => 'integer',
+ 'location_id' => 'integer',
+ 'company_id' => 'integer',
];
/**
@@ -71,7 +74,8 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
'password' => 'required|min:8',
'locale' => 'max:10|nullable',
'website' => 'url|nullable',
- 'manager_id' => 'nullable|different:id',
+ 'manager_id' => 'nullable|exists:users,id|different:users.id',
+ 'location_id' => 'exists:locations,id|nullable',
];
use Searchable;