变更
This commit is contained in:
+11
-6
@@ -26,13 +26,18 @@ class UniqueValidator extends BaseValidator
|
|||||||
if (!$this->model->getIsNowExample()) {
|
if (!$this->model->getIsNowExample()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return $this->_validator($this->field, function ($field, $params, $model) {
|
return $this->_validator($this->field, function ($_item, $params, $model) {
|
||||||
if (!isset($params[$field])) {
|
if (!is_array($_item)) {
|
||||||
return true;
|
$_item = [$_item];
|
||||||
}
|
}
|
||||||
$param = $params[$field];
|
$data = array_reduce($_item, function ($resp, $next) use ($params) {
|
||||||
if ($model::query()->where([$field => $param])->exists()) {
|
$array = empty($resp) ? [] : $resp;
|
||||||
return $this->addError($field,'The :attribute \'' . $param . '\' is exists!');
|
$array[$next] = $params[$next] ?? null;
|
||||||
|
return $array;
|
||||||
|
});
|
||||||
|
if ($model::query()->where($data)->exists()) {
|
||||||
|
return $this->addError(implode(',', $_item),
|
||||||
|
'The :attribute \'' . implode(',', $_item) . '\' is exists!');
|
||||||
}
|
}
|
||||||
return $this->isFail = TRUE;
|
return $this->isFail = TRUE;
|
||||||
}, $this->params, $this->model);
|
}, $this->params, $this->model);
|
||||||
|
|||||||
Reference in New Issue
Block a user