Added type casting and a few more validation rules

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2020-04-22 06:37:40 -07:00
parent a44d1cc0cf
commit fa5134603f
No known key found for this signature in database
GPG key ID: 10BFFDA3ED34B5AC
8 changed files with 52 additions and 9 deletions

View file

@ -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 = [ protected $rules = [
'name' => 'max:255|nullable', 'name' => 'max:255|nullable',
@ -86,7 +94,9 @@ class Asset extends Depreciable
'physical' => 'numeric|max:1|nullable', 'physical' => 'numeric|max:1|nullable',
'checkout_date' => 'date|max:10|min:10|nullable', 'checkout_date' => 'date|max:10|min:10|nullable',
'checkin_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', 'asset_tag' => 'required|min:1|max:255|unique_undeleted',
'status' => 'integer', 'status' => 'integer',
'serial' => 'unique_serial|nullable', 'serial' => 'unique_serial|nullable',

View file

@ -24,6 +24,12 @@ class Category extends SnipeModel
protected $table = 'categories'; protected $table = 'categories';
protected $hidden = ['user_id','deleted_at']; protected $hidden = ['user_id','deleted_at'];
protected $casts = [
'user_id' => 'integer',
];
/** /**
* Category validation rules * Category validation rules
*/ */

View file

@ -20,10 +20,15 @@ class Consumable extends SnipeModel
protected $dates = ['deleted_at', 'purchase_date']; protected $dates = ['deleted_at', 'purchase_date'];
protected $table = 'consumables'; protected $table = 'consumables';
protected $casts = [ protected $casts = [
'requestable' => 'boolean' 'requestable' => 'boolean',
'category_id' => 'integer',
'company_id' => 'integer',
'qty' => 'integer',
'min_amt' => 'integer',
]; ];
/** /**
* Category validation rules * Category validation rules
*/ */

View file

@ -19,6 +19,12 @@ class Department extends SnipeModel
use ValidatingTrait, UniqueUndeletedTrait; use ValidatingTrait, UniqueUndeletedTrait;
protected $casts = [
'manager_id' => 'integer',
'location_id' => 'integer',
'company_id' => 'integer',
];
protected $rules = [ protected $rules = [
'name' => 'required|max:255', 'name' => 'required|max:255',
'location_id' => 'numeric|nullable', 'location_id' => 'numeric|nullable',

View file

@ -36,6 +36,13 @@ class License extends Depreciable
protected $guarded = 'id'; protected $guarded = 'id';
protected $table = 'licenses'; protected $table = 'licenses';
protected $casts = [
'seats' => 'integer',
'category_id' => 'integer',
'company_id' => 'integer',
];
protected $rules = array( protected $rules = array(
'name' => 'required|string|min:3|max:255', 'name' => 'required|string|min:3|max:255',
'seats' => 'required|min:1|max:999|integer', 'seats' => 'required|min:1|max:999|integer',

View file

@ -27,9 +27,14 @@ class Location extends SnipeModel
'address2' => 'max:80|nullable', 'address2' => 'max:80|nullable',
'zip' => 'min:3|max:10|nullable', 'zip' => 'min:3|max:10|nullable',
'manager_id' => 'exists:users,id|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 * Whether the model should inject it's identifier to the unique
* validation rules before attempting validation. If this property * validation rules before attempting validation. If this property

View file

@ -56,6 +56,9 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
protected $casts = [ 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', 'password' => 'required|min:8',
'locale' => 'max:10|nullable', 'locale' => 'max:10|nullable',
'website' => 'url|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; use Searchable;