I have a rule class with a message like this
public function message()
{
return 'The value you have entered is invalid.';
}
But I don't know how to do that
Validator::extend('enum_key', function ($attribute, $value, $parameters, $validator) {
$enum = $parameters[0] ?? null;
return (new EnumKey($enum))->passes($attribute, $value);
});
Here is my solution
Validator::extend('enum_key', function ($attribute, $value, $parameters, $validator) {
$enum = $parameters[0] ?? null;
return (new EnumKey($enum))->passes($attribute, $value);
}, ((new \ReflectionClass(EnumKey::class))->newInstanceWithoutConstructor())->message());
But as you can see it's messy, what's a cleaner solution?
Aucun commentaire:
Enregistrer un commentaire