mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-10 00:22:48 +08:00
改进Validate
This commit is contained in:
@@ -317,7 +317,12 @@ class Validate
|
||||
$value = $this->getDataValue($data, $key);
|
||||
|
||||
// 字段验证
|
||||
if ($rule instanceof \Closure) {
|
||||
// 匿名函数验证 支持传入当前字段和所有字段两个数据
|
||||
$result = call_user_func_array($rule, [$value, $data]);
|
||||
} else {
|
||||
$result = $this->checkItem($key, $value, $rule, $data, $title, $msg);
|
||||
}
|
||||
|
||||
if (true !== $result) {
|
||||
// 没有返回true 则表示验证失败
|
||||
@@ -350,10 +355,6 @@ class Validate
|
||||
*/
|
||||
protected function checkItem($field, $value, $rules, $data, $title = '', $msg = [])
|
||||
{
|
||||
if ($rules instanceof \Closure) {
|
||||
// 匿名函数验证 支持传入当前字段和所有字段两个数据
|
||||
$result = call_user_func_array($rules, [$value, $data]);
|
||||
} else {
|
||||
// 支持多规则验证 require|in:a,b,c|... 或者 ['require','in'=>'a,b,c',...]
|
||||
if (is_string($rules)) {
|
||||
$rules = explode('|', $rules);
|
||||
@@ -416,7 +417,6 @@ class Validate
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user