diff --git a/src/AttributeEvents.php b/src/AttributeEvents.php index 4532577..ed0bd8c 100644 --- a/src/AttributeEvents.php +++ b/src/AttributeEvents.php @@ -61,7 +61,7 @@ private function fireAttributeEvents(): void || $expected === 'false' && $value === false || is_numeric($expected) && Str::contains($expected, '.') && $value === (float) $expected // float || is_numeric($expected) && $value === (int) $expected // int - || (string) $value === $expected + || $this->canBeCastedToString($value) && (string) $value === $expected ) { $this->fireModelEvent($change, false); } @@ -137,4 +137,16 @@ private function hasAccessor(string $attribute): bool return false; } + + private function canBeCastedToString($value): bool + { + if ($value instanceof \UnitEnum) { + return false; + } + + return is_scalar($value) + || is_null($value) + || is_array($value) + || is_object($value) && method_exists($value, '__toString'); + } }