Valitron\Validator::errors PHP Method

errors() public method

Get array of error messages
public errors ( null | string $field = null ) : array | boolean
$field null | string
return array | boolean
    public function errors($field = null)
    {
        if ($field !== null) {
            return isset($this->_errors[$field]) ? $this->_errors[$field] : false;
        }
        return $this->_errors;
    }

Usage Example

 /**
  * Fix bug where rules messages added with Validator::addRule were replaced after creating validator instance
  */
 public function testRuleMessagesReplacedAfterConstructor()
 {
     $customMessage = 'custom message';
     $ruleName = 'customRule';
     $fieldName = 'fieldName';
     Validator::addRule($ruleName, function () {
     }, $customMessage);
     $v = new Validator(array($fieldName => $fieldName));
     $v->rule($ruleName, $fieldName);
     $v->validate();
     $messages = $v->errors();
     $this->assertArrayHasKey($fieldName, $messages);
     $this->assertEquals(ucfirst("{$fieldName} {$customMessage}"), $messages[$fieldName][0]);
 }
All Usage Examples Of Valitron\Validator::errors