public getMessage ( ) : string | ||
Résultat | 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);
}
/** * 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()); }