Skip to content

Commit

Permalink
refactor: Update enum handling in LogsActivity for Laravel 11 compati…
Browse files Browse the repository at this point in the history
…bility
  • Loading branch information
StevePorter92 authored and freekmurze committed Mar 8, 2024
1 parent 2caf20d commit af305c9
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Traits/LogsActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}

Expand Down

0 comments on commit af305c9

Please sign in to comment.