mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 15:42:48 +08:00
改进模型数据验证
This commit is contained in:
@@ -1043,6 +1043,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 数据自动验证
|
// 数据自动验证
|
||||||
|
if (!empty($data)) {
|
||||||
if (!$this->validateData($data)) {
|
if (!$this->validateData($data)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1051,6 +1052,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
$this->setAttr($key, $value, $data);
|
$this->setAttr($key, $value, $data);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($where)) {
|
if (!empty($where)) {
|
||||||
$this->isUpdate = true;
|
$this->isUpdate = true;
|
||||||
|
|||||||
@@ -202,10 +202,9 @@ class HasMany extends Relation
|
|||||||
*/
|
*/
|
||||||
public function save($data)
|
public function save($data)
|
||||||
{
|
{
|
||||||
$model = $this->make();
|
$model = $this->make($data);
|
||||||
$data = array_merge($model->getData(), $data);
|
|
||||||
|
|
||||||
return $model->save($data) ? $model : false;
|
return $model->save() ? $model : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -245,10 +245,9 @@ class MorphMany extends Relation
|
|||||||
*/
|
*/
|
||||||
public function save($data)
|
public function save($data)
|
||||||
{
|
{
|
||||||
$model = $this->make();
|
$model = $this->make($data);
|
||||||
$data = array_merge($model->getData(), $data);
|
|
||||||
|
|
||||||
return $model->save($data) ? $model : false;
|
return $model->save() ? $model : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -199,10 +199,9 @@ class MorphOne extends Relation
|
|||||||
*/
|
*/
|
||||||
public function save($data)
|
public function save($data)
|
||||||
{
|
{
|
||||||
$model = $this->make();
|
$model = $this->make($data);
|
||||||
$data = array_merge($model->getData(), $data);
|
|
||||||
|
|
||||||
return $model->save($data) ? $model : false;
|
return $model->save() ? $model : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user