This commit is contained in:
2023-12-18 15:01:09 +08:00
parent d860269a7c
commit 645d73453c
15 changed files with 251 additions and 613 deletions
+4 -12
View File
@@ -13,23 +13,15 @@ use Exception;
class RoundValidator extends BaseValidator
{
public ?int $value = null;
/**
* @param string $field
* @param mixed $value
* @return bool
* @throws
*/
public function trigger(): bool
public function trigger(string $field, mixed $value): bool
{
return $this->_validator($this->field, function ($field, $model, $param) {
$value = $model->getAttribute($field);
if ($value == null || round($value, $param) != $value) {
return $this->addError($field, 'The param :attribute length error');
}
return true;
}, $this->model, $this->value);
return round($value, $this->value) == $value;
}