feat(validation): Add human-readable validation error messages

This commit is contained in:
kj
2026-09-03 15:58:49 -03:00
parent f475c9125f
commit aca4e732ed
2 changed files with 135 additions and 5 deletions

View File

@@ -84,11 +84,11 @@ class Request extends Neuron
return true;
}
if (isset(static::messages()[Validator::$lastFailed])) {
$error = static::messages()[Validator::$lastFailed];
} else {
$error = 'Error: validation failed of ' . preg_replace('/\./', ' as ', Validator::$lastFailed, 1);
}
$error = Validator::message(
Validator::$lastFailed,
static::messages(),
static::attributes()
);
static::onInvalid($error);
return false;
@@ -134,6 +134,19 @@ class Request extends Neuron
return [];
}
/**
* Human-readable names for the fields.
*
* Forwarded to Validator::message() so the :attribute marker in the error
* text can be replaced with a friendlier name (e.g. "edad" => "la edad").
*
* @return array
*/
public function attributes(): array
{
return [];
}
/**
* Function to execute when an invalid value has been detected.
*