robertogallea / laravel-codicefiscale

Codice fiscale validation for php/laravel
MIT License
42 stars 16 forks source link

Allows Customizing The Validation Attributes #42

Closed JBou closed 2 years ago

JBou commented 2 years ago

Description

This commit allows Customizing The Validation Attributes and supports translated attribute names

Motivation and context

Before this PR it was not possible to change the displayed name of the field when using the validator to validate an input field. The error message always showed the name of the input field, for example: The tax_number contains bad omocodia characters Now you can change the displayed name of the attribute and you can even translate it. The codice fiscale contains bad omocodia characters

How has this been tested?

using this code:

/**
 * Get custom attributes for validator errors.
 *
 * @return array
 */
public function attributes()
{
    return [
        'tax_number' => 'codice fiscale',
    ];
}

i tried it using the validator, it successfully changed the name of the attribute as written above.

Screenshots (if appropriate)

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

Checklist:

JBou commented 2 years ago

Should I include a short documentation at the end of this paragraph (just a sentence with a link to Customizing The Validation Attributes) or is it okay as it is?

robertogallea commented 2 years ago

Hi Gabriel, thank you for this contribution. I don't think that additional documentation is required, since this PR leverages the standard laravel features. Indeed, I guess it was your starting point, you tried to override the attributes() method of the request and nothing happened, right?

JBou commented 2 years ago

Exactly, that was my starting point. Thanks for merging!