This commit is contained in:
2021-10-09 16:48:19 +08:00
parent 2c6d216953
commit 97c07dabeb
2 changed files with 5 additions and 5 deletions
+4 -4
View File
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace validator; namespace validator;
use Database\ActiveRecord; use Database\Model;
use Exception; use Exception;
abstract class BaseValidator abstract class BaseValidator
@@ -22,7 +22,7 @@ abstract class BaseValidator
protected array $params = []; protected array $params = [];
protected ?ActiveRecord $model = null; protected ?Model $model = null;
/** /**
@@ -34,9 +34,9 @@ abstract class BaseValidator
} }
/** /**
* @return ActiveRecord|null * @return Model|null
*/ */
public function getModel(): ?ActiveRecord public function getModel(): ?Model
{ {
return $this->model; return $this->model;
} }
+1 -1
View File
@@ -33,7 +33,7 @@ class UniqueValidator extends BaseValidator
if (!$this->model->getIsCreate()) { if (!$this->model->getIsCreate()) {
return true; return true;
} }
if ($model::find()->where([$this->field => $param[$this->field]])->exists()) { if ($model::query()->where([$this->field => $param[$this->field]])->exists()) {
return $this->addError('The :attribute \'' . $param[$this->field] . '\' is exists!'); return $this->addError('The :attribute \'' . $param[$this->field] . '\' is exists!');
} }
return $this->isFail = TRUE; return $this->isFail = TRUE;