From ff5a95a6a40281ccb710fdda99a8aaad666b46ae Mon Sep 17 00:00:00 2001 From: andreaci Date: Wed, 23 Mar 2022 17:23:53 +0100 Subject: [PATCH] next_audit_date error on saving asset Solved error 500 when saving new Asset and no next_audit_date is defined --- app/Observers/AssetObserver.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php index 85e33ee045..3c23f59c83 100644 --- a/app/Observers/AssetObserver.php +++ b/app/Observers/AssetObserver.php @@ -17,12 +17,15 @@ class AssetObserver */ public function updating(Asset $asset) { - + $attributes = $asset->getAttributes(); + $attributesOriginal = $asset->getAttributes(); + // If the asset isn't being checked out or audited, log the update. // (Those other actions already create log entries.) - if (($asset->getAttributes()['assigned_to'] == $asset->getOriginal()['assigned_to']) - && ($asset->getAttributes()['next_audit_date'] == $asset->getOriginal()['next_audit_date']) - && ($asset->getAttributes()['last_checkout'] == $asset->getOriginal()['last_checkout'])) { + if (($attributes['assigned_to'] == $attributesOriginal['assigned_to']) + && ((isset( $attributes['next_audit_date']) ? $attributes['next_audit_date'] : null) == (isset($attributesOriginal['next_audit_date']) ? $attributesOriginal['next_audit_date']: null)) + && ($attributes['last_checkout'] == $attributesOriginal['last_checkout'])) { + $changed = []; foreach ($asset->getOriginal() as $key => $value) {