From e37035eed85b6be553a49a1939b9569278ce1cd8 Mon Sep 17 00:00:00 2001 From: kj Date: Sat, 13 Jun 2026 16:48:07 -0300 Subject: [PATCH] fix(model): support both backed and unit enums --- src/Libs/Model.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Libs/Model.php b/src/Libs/Model.php index 3cbbfad..0fdee88 100644 --- a/src/Libs/Model.php +++ b/src/Libs/Model.php @@ -300,8 +300,15 @@ class Model foreach ($elem as $key => $value) { $index = array_search($key, $propertyNames); if (is_numeric($index)) { - if (enum_exists($properties[$index]->getType()->getName())) { - $instance->{$properties[$index]->name} = $properties[$index]->getType()->getName()::tryfrom($value); + $type = $properties[$index]->getType(); + if (enum_exists($type->getName())) { + if (method_exists($type->getName(), 'tryFrom')) { + $instance->{$properties[$index]->name} = $type->getName()::tryfrom($value); + } elseif ( + in_array($value, array_column($type->getName()::cases(), 'name')) + ) { + $instance->{$properties[$index]->name} = $type->getName()::{$value}; + } } else { $instance->{$properties[$index]->name} = $value; }