From 3152df2c48bf5d1f01c9e66bb9d9b84c7a06a6d4 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 29 Nov 2023 10:07:47 +0000 Subject: [PATCH] Created mutator for requestable attribute Signed-off-by: snipe --- app/Models/Asset.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index f23ff52f64ac..029f449d50f6 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -921,6 +921,27 @@ public function getComponentCost(){ return $cost; } + /** + * ----------------------------------------------- + * BEGIN MUTATORS + * ----------------------------------------------- + **/ + + /** + * This sets the requestable to a boolean 0 or 1. This accounts for forms or API calls that + * explicitly pass the requestable field but it has a null or empty value. + * + * This will also correctly parse a 1/0 if "true"/"false" is passed. + * + * @param $value + * @return void + */ + public function setRequestableAttribute($value) + { + $this->attributes['requestable'] = (int) filter_var($value, FILTER_VALIDATE_BOOLEAN); + } + + /** * ----------------------------------------------- * BEGIN QUERY SCOPES