MongolidLaravel\MongolidModel::isValid PHP Method

isValid() public method

Verify if the model is valid by running its validation rules, defined on static attribute $rules.
public isValid ( ) : boolean
return boolean
    public function isValid()
    {
        // Return true if there aren't validation rules
        if (!is_array(static::$rules)) {
            return true;
        }
        // Get the attributes and the rules to validate then
        $attributes = $this->attributes;
        $rules = static::$rules;
        // Verify attributes that are hashed and that have not changed
        // those doesn't need to be validated.
        foreach ($this->hashedAttributes as $hashedAttr) {
            if (isset($this->original[$hashedAttr]) && $this->{$hashedAttr} == $this->original[$hashedAttr]) {
                unset($rules[$hashedAttr]);
            }
        }
        // Creates validator with attributes and the rules of the object
        $validator = app(ValidationFactory::class)->make($attributes, $rules);
        // Validate and attach errors
        if ($hasErrors = $validator->fails()) {
            $this->errors = $validator->errors();
        }
        return !$hasErrors;
    }