mardi 20 novembre 2018

How to define field specific error message or overwrite the default one for a custom validation rule used in a FormRequest in Laravel 5.5

I have created a custom validation rule and I am using it to validate a data field in a FormRequest.

However, I would like to use a different message for this field and not the default message that is set in the Rule's message() method.

So, I tried using the method messages() inside of the FormRequest using a key of the field name and the rule (in snake case)

return ["{$field}.{$rule}" => 'My custom message'];

The error message did not change, I investigated a little inside the code of the validator and I found out that for custom rules, it uses the method validateUsingCustomRule that doesn't seem to care about custom messages.

Any ideas on how it can be overwritten or what would be the best way to do it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire