From bdbfb0f2a174a7f1a147ce0b6ab11a45e5efda38 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 15 May 2024 14:21:16 +0100 Subject: [PATCH] Added accessor and mutator for next_audit_date Signed-off-by: snipe --- app/Models/Asset.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index c5373a04e2..b2c84497a4 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -944,6 +944,25 @@ class Asset extends Depreciable * ----------------------------------------------- **/ + /** + * Make sure the next_audit_date is formatted as Y-m-d. + * + * This is kind of dumb and confusing, since we already cast it that way AND it's a date field + * in the database, but here we are. + * + * @param $value + * @return void + */ + public function getNextAuditDateAttribute($value) + { + return $this->attributes['next_audit_date'] = $value ? Carbon::parse($value)->format('Y-m-d') : null; + } + + public function setNextAuditDateAttribute($value) + { + $this->attributes['next_audit_date'] = $value ? Carbon::parse($value)->format('Y-m-d') : null; + } + /** * 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.