From af305c96c0338c2c96f6fc8e68570d947f69f85b Mon Sep 17 00:00:00 2001 From: Steve Porter Date: Thu, 8 Feb 2024 20:52:52 +0000 Subject: [PATCH] refactor: Update enum handling in LogsActivity for Laravel 11 compatibility --- src/Traits/LogsActivity.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Traits/LogsActivity.php b/src/Traits/LogsActivity.php index 770ada80..f8b1afdf 100644 --- a/src/Traits/LogsActivity.php +++ b/src/Traits/LogsActivity.php @@ -366,14 +366,13 @@ public static function logChanges(Model $model): array if ($model->hasCast($attribute)) { $cast = $model->getCasts()[$attribute]; - if (function_exists('enum_exists') && enum_exists($cast)) { - if (method_exists($model, 'getStorableEnumValue')) { + if ($model->isEnumCastable($attribute)) { + try { $changes[$attribute] = $model->getStorableEnumValue($changes[$attribute]); - } else { - // ToDo: DEPRECATED - only here for Laravel 8 support - $changes[$attribute] = $changes[$attribute] instanceof \BackedEnum - ? $changes[$attribute]->value - : $changes[$attribute]->name; + } catch (\ArgumentCountError $e) { + // In Laravel 11, this method has an extra argument + // https://github.com/laravel/framework/pull/47465 + $changes[$attribute] = $model->getStorableEnumValue($cast, $changes[$attribute]); } }