Garden\Validation::getMessage PHP Method

getMessage() public method

Get the message for this exception.
public getMessage ( ) : string
return string Returns the exception message.
    public function getMessage()
    {
        if ($this->mainMessage) {
            return $this->mainMessage;
        }
        // Generate the message by concatenating all of the errors together.
        $messages = [];
        foreach ($this->errors as $errors) {
            foreach ($errors as $error) {
                $field = val('field', $error, '*');
                if (is_array($field)) {
                    $field = implode(', ', $field);
                }
                if (isset($error['message'])) {
                    $message = $error['message'];
                } elseif (strpos($error['code'], '%s') === false) {
                    $message = sprintft($error['code'] . ': %s.', $field);
                } else {
                    $message = sprintft($error['code'], $field);
                }
                $messages[] = $message;
            }
        }
        return implode(' ', $messages);
    }

Usage Example

 /**
  * Initialize an instance of the {@link ValidationException} class.
  *
  * @param Validation $validation The {@link Validation} object for the exception.
  */
 public function __construct(Validation $validation)
 {
     $this->validation = $validation;
     parent::__construct($validation->getMessage(), (int) $validation->status());
 }