diff --git a/src/Model.php b/src/Model.php index 331e797f..78dc59b9 100644 --- a/src/Model.php +++ b/src/Model.php @@ -231,9 +231,9 @@ public function invoke($method, array $vars = []) /** * 架构函数. * - * @param array|Model $data 数据 + * @param array|object $data 数据 */ - public function __construct(array|Model $data = []) + public function __construct(array|object $data = []) { // 设置数据 $this->data($data); diff --git a/src/model/concern/Attribute.php b/src/model/concern/Attribute.php index 35eadb55..0b942323 100644 --- a/src/model/concern/Attribute.php +++ b/src/model/concern/Attribute.php @@ -221,16 +221,18 @@ protected function getRealFieldName(string $name): string /** * 设置数据对象值 * - * @param array|Model $data 数据 + * @param array|object $data 数据 * @param bool $set 是否调用修改器 * @param array $allow 允许的字段名 * * @return $this */ - public function data(array|Model $data, bool $set = false, array $allow = []) + public function data(array|object $data, bool $set = false, array $allow = []) { if ($data instanceof Model) { $data = $data->getData(); + } elseif (is_object($data)) { + $data = get_object_vars($data); } // 清空数据