ActiveRecord\Errors::to_array PHP Method

to_array() public method

$model->errors->errors(); # array( # "name" => array("Name can't be blank"), # "state" => array("State is the wrong length (should be 2 chars)") # )
public to_array ( callable $closure = null ) : array
$closure callable Closure to fetch the errors in some other format (optional) This closure has the signature function($attribute, $message) and is called for each available error message.
return array
    public function to_array($closure = null)
    {
        $errors = array();
        if ($this->errors) {
            foreach ($this->errors as $attribute => $messages) {
                foreach ($messages as $msg) {
                    if (is_null($msg)) {
                        continue;
                    }
                    $errors[$attribute][] = $message = Utils::human_attribute($attribute) . ' ' . $msg;
                    if ($closure) {
                        $closure($attribute, $message);
                    }
                }
            }
        }
        return $errors;
    }