diff --git a/extend/catcher/base/CatchModel.php b/extend/catcher/base/CatchModel.php index 52adb78..c47b7e4 100644 --- a/extend/catcher/base/CatchModel.php +++ b/extend/catcher/base/CatchModel.php @@ -5,6 +5,7 @@ namespace catcher\base; use catcher\CatchQuery; use catcher\traits\db\BaseOptionsTrait; +use catcher\traits\db\RewriteTrait; use catcher\traits\db\TransTrait; use think\model\concern\SoftDelete; use catcher\traits\db\ScopeTrait; @@ -17,7 +18,7 @@ use catcher\traits\db\ScopeTrait; */ abstract class CatchModel extends \think\Model { - use SoftDelete, TransTrait, BaseOptionsTrait, ScopeTrait; + use SoftDelete, TransTrait, BaseOptionsTrait, ScopeTrait, RewriteTrait; protected $createTime = 'created_at'; @@ -29,8 +30,8 @@ abstract class CatchModel extends \think\Model protected $autoWriteTimestamp = true; + // 分页 Limit public const LIMIT = 10; - // 开启 public const ENABLE = 1; // 禁用 diff --git a/extend/catcher/traits/db/RewriteTrait.php b/extend/catcher/traits/db/RewriteTrait.php new file mode 100644 index 0000000..8dfc628 --- /dev/null +++ b/extend/catcher/traits/db/RewriteTrait.php @@ -0,0 +1,56 @@ +hidden = array_merge($this->hidden, $this->defaultHiddenFields()); + } + + /** + * hidden model fields + * + * @return array + */ + protected function defaultHiddenFields(): array + { + return [$this->deleteTime]; + } + + /** + * 重写 hidden 方法,支持合并 hidden 属性 + * + * @param array $hidden + * @return $this + */ + public function hidden(array $hidden = []) + { + /** + * 合并属性 + */ + if (!count($this->hidden)) { + $this->hidden = array_merge($this->hidden, $hidden); + + return $this; + } + + $this->hidden = $hidden; + + return $this; + } +} \ No newline at end of file