Skip to content

Commit e24fd68

Browse files
author
Stiven Katuuk
committed
fix: with property cannot perform non-backed enum
1 parent 6115677 commit e24fd68

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/ActivityLogger.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public function withProperties(mixed $properties): static
109109

110110
public function withProperty(string $key, mixed $value): static
111111
{
112+
if (is_object($value) && function_exists('enum_exists') && enum_exists(get_class($value))) {
113+
$value = $value->value ?? $value->name;
114+
}
115+
112116
$this->getActivity()->properties = $this->getActivity()->properties->put($key, $value);
113117

114118
return $this;

tests/AbleStoreNonBackedEnumTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
use Spatie\Activitylog\Test\Enum\NonBackedEnum;
66
use Spatie\Activitylog\Test\Models\Activity;
7+
use Spatie\Activitylog\Test\Models\User;
78

89
it('can store non backed enum', function () {
910
$description = 'ROLE LOG';
1011

11-
activity()->withProperty('role', NonBackedEnum::User)->log($description);
12+
activity()
13+
->performedOn(User::first())
14+
->withProperty('role', NonBackedEnum::User)->log($description);
1215

1316
expect(Activity::query()->latest()->first()->description)->toEqual($description);
1417
});

0 commit comments

Comments
 (0)