Best way to provide custom validation error messages for a field depending on context
I'm trying to figure out the best way to customize my validation errors for a given field depending on context.
Ex: I have a field username which is required in both a login and a registration form. I want the error message to be different on both forms. On the login form - "Your username is required." on the registration form "A username is required."
I know I can pass a 3rd argument to Validator:make with my custom messages in my controller, but this seems dirty. I would rather keep all my messages in language files if possible.
The problem with using custom fields in the validation.php file is that there does not seem to be a way to have context.
'custom' => [
'attribute-name' => [
'rule-name' => 'custom-message',
],
],
Please or to participate in this conversation.