Closed Bruce-chai closed 1 year ago
translate fuction
function translate($message) // message = {{name}} must not be empty
{
// your translation code
return str_replace($message, 'O campo {{name}} não pode ser vazio.', $message);
}
binding translate function to factory
Factory::setDefaultInstance(
(new Factory())->withTranslator('translate')
);
validate and get message
try {
$value = [];
Validator::notEmpty()->setName('cidades')->check($value); // cidades = cities
} catch (Throwable $e){
echo $e->getMessage(); // result - O campo cidades não pode ser vazio.
}
Closed: asked and answered
How to define different error messages for the same rule for different fields