diff --git a/library/think/Validate.php b/library/think/Validate.php index 0b97e64d..73412b7c 100644 --- a/library/think/Validate.php +++ b/library/think/Validate.php @@ -315,8 +315,8 @@ class Validate // 字段验证 if ($rule instanceof \Closure) { - // 匿名函数验证 - $result = call_user_func_array($rule, [$value, $data, $title, $msg, $this]); + // 匿名函数验证 支持传入当前字段和所有字段两个数据 + $result = call_user_func_array($rule, [$value, $data]); } else { $result = $this->checkItem($key, $value, $rule, $data, $title, $msg); } @@ -1113,10 +1113,12 @@ class Validate * @access protected * @param mixed $value 字段值 * @param mixed $rule 验证规则 + * @param array $data 数据 * @return bool */ - protected function after($value, $rule) + protected function after($value, $rule, $data) { + $rule = $this->getDataValue($data, $rule); return strtotime($value) >= strtotime($rule); } @@ -1125,10 +1127,12 @@ class Validate * @access protected * @param mixed $value 字段值 * @param mixed $rule 验证规则 + * @param array $data 数据 * @return bool */ - protected function before($value, $rule) + protected function before($value, $rule, $data) { + $rule = $this->getDataValue($data, $rule); return strtotime($value) <= strtotime($rule); } @@ -1247,7 +1251,7 @@ class Validate list($name1, $name2) = explode('.', $key); $value = isset($data[$name1][$name2]) ? $data[$name1][$name2] : null; } else { - $value = isset($data[$key]) ? $data[$key] : null; + $value = isset($data[$key]) ? $data[$key] : $key; } return $value; } diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 787edc07..64629c0f 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -29,6 +29,8 @@ class BelongsToMany extends Relation protected $pivotName; // 中间表模型对象 protected $pivot; + // 中间表数据名称 + protected $pivotDataName = 'pivot'; /** * 构造函数 @@ -70,6 +72,18 @@ class BelongsToMany extends Relation return $this; } + /** + * 设置中间表数据名称 + * @access public + * @param string $name + * @return $this + */ + public function pivotDataName($name) + { + $this->pivotDataName = $name; + return $this; + } + /** * 获取中间表更新条件 * @param $data @@ -118,7 +132,7 @@ class BelongsToMany extends Relation } } } - $model->setRelation('pivot', $this->newPivot($pivot, true)); + $model->setRelation($this->pivotDataName, $this->newPivot($pivot, true)); } } @@ -384,7 +398,7 @@ class BelongsToMany extends Relation } } } - $set->setRelation('pivot', $this->newPivot($pivot, true)); + $set->setRelation($this->pivotDataName, $this->newPivot($pivot, true)); $data[$pivot[$this->localKey]][] = $set; } return $data;