From d3dbd82ce2118ff0adc23de5f822fcb08fa04414 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Tue, 22 Apr 2025 14:20:01 +0100 Subject: [PATCH] Check that array key exists before accessing it --- app/Models/Loggable.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index 506eb116b..4cf581766 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -100,13 +100,15 @@ trait Loggable foreach ($originalValues as $key => $value) { + // TODO - action_date isn't a valid attribute of any first-class object, so we might want to remove this? if ($key == 'action_date' && $value != $action_date) { $changed[$key]['old'] = $value; $changed[$key]['new'] = is_string($action_date) ? $action_date : $action_date->format('Y-m-d H:i:s'); - } elseif ($value != $this->getAttributes()[$key]) { + } elseif (array_key_exists($key, $this->getAttributes()) && $value != $this->getAttributes()[$key]) { $changed[$key]['old'] = $value; $changed[$key]['new'] = $this->getAttributes()[$key]; } + // NOTE - if the attribute exists in $originalValues, but *not* in ->getAttributes(), it isn't added to $changed } if (!empty($changed)){