Skip to content

Commit

Permalink
增加enumReadName属性
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Sep 10, 2024
1 parent 8fe6045 commit a306c8e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/model/concern/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ trait Attribute
*/
protected $jsonAssoc = false;

/**
* Enum数据取出自动转换为name.
*
* @var bool
*/
protected $enumReadName = false;

/**
* 是否严格字段大小写.
*
Expand Down Expand Up @@ -651,6 +658,8 @@ protected function readTransform($value, string | array $type)
$value = $type::from($value);
if (is_subclass_of($type, EnumTransform::class)) {
$value = $value->value();
} elseif ($this->enumReadName) {
$value = $value->name;
}
} else {
// 对象类型
Expand Down

0 comments on commit a306c8e

Please sign in to comment.