Skip to content

Commit

Permalink
hidden方法支持隐藏json字段的某个属性 hidden(['info.name'])
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Sep 4, 2024
1 parent fd9ca44 commit 97df399
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/model/concern/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ public function toArray(): array
$item[$key] = $this->getAttr($key);
} elseif (!isset($hidden[$key]) && !$hasVisible) {
$item[$key] = $this->getAttr($key);
} elseif (in_array($key, $this->json)) {
foreach ($hidden[$key] as $name) {
if (is_array($val)) {
unset($val[$name]);
} else {
unset($val->$name);
}
}
$item[$key] = $val;
}

if (isset($this->mapping[$key])) {
Expand Down

1 comment on commit 97df399

@WuYunlong
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个新增功能没有考虑全部排除掉的情况

 protected $json = ['ext_data'];
 protected $hidden = ['delete_at', 'ext_data'];

Please sign in to comment.