feat(validation): Add human-readable validation error messages
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user