Skip to content

Commit

Permalink
改进数据集withattr方法
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Sep 3, 2024
1 parent 302e683 commit a7c1324
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/model/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function setParent(Model $parent)
public function withAttr(string|array $name, callable $callback = null)
{
$this->each(function (Model $model) use ($name, $callback) {
$model->withAttr($name, $callback);
$model->withFieldAttr($name, $callback);
});

return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/model/concern/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ trait Attribute
* 自动写入字段.
*
* @var array
*/
*/
protected $autoInsertFields = [];

/**
Expand Down Expand Up @@ -587,9 +587,9 @@ protected function getJsonValue(string $name, $value)

foreach ($this->withAttr[$name] as $key => $closure) {
if ($this->jsonAssoc) {
$value[$key] = $closure($value[$key], $value);
$value[$key] = $closure($value[$key] ?? '', $value);
} else {
$value->$key = $closure($value->$key, $value);
$value->$key = $closure($value->$key ?? '', $value);
}
}

Expand Down

0 comments on commit a7c1324

Please sign in to comment.