diff --git a/src/Base/Model.php b/src/Base/Model.php index f9fd276..37a6218 100644 --- a/src/Base/Model.php +++ b/src/Base/Model.php @@ -24,6 +24,7 @@ use Database\HasOne; use Database\ModelInterface; use Database\Mysql\Columns; use Database\Relation; +use Database\SqlBuilder; use Database\Traits\HasBase; use Exception; use JetBrains\PhpStorm\Pure; @@ -97,6 +98,12 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T protected string $connection = 'db'; + /** + * @var array + */ + protected array $rules = []; + + /** * @var Relation|null */ @@ -183,7 +190,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T /** * @param $data - * @return ModelInterface + * @return Model */ public function setWith($data): static { @@ -620,7 +627,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T if (!is_null($data)) { $this->_attributes = merge($this->_attributes, $data); } - if (!$this->validator($this->rules()) || !$this->beforeSave($this)) { + if (!$this->validator($this->rules) || !$this->beforeSave($this)) { return false; } [$change, $condition, $fields] = $this->separation(); @@ -632,11 +639,11 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T /** - * @param array $rule + * @param array|null $rule * @return bool * @throws Exception */ - public function validator(array $rule): bool + public function validator(?array $rule): bool { if (empty($rule)) return true; $validate = $this->resolve($rule); diff --git a/src/Model.php b/src/Model.php index 3344ab5..e8b61af 100644 --- a/src/Model.php +++ b/src/Model.php @@ -32,14 +32,6 @@ class Model extends Base\Model { - /** - * @return array - */ - public function rules(): array - { - return []; - } - /** * @param string $column * @param int $value