diff --git a/library/think/Model.php b/library/think/Model.php index 8e460ee9..714b4277 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -60,6 +60,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected $pk; // 数据表字段信息 留空则自动获取 protected $field = []; + // 只读字段 + protected $readonly = []; // 显示属性 protected $visible = []; // 隐藏属性 @@ -663,6 +665,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess } } + if (!empty($this->readonly)) { + // 只读字段不允许更新 + foreach ($this->readonly as $key => $field) { + if (isset($data[$field])) { + unset($data[$field]); + } + } + } + if (empty($where) && !empty($this->updateWhere)) { $where = $this->updateWhere; }