How do I change the validation message?

Asked 2 years ago, Updated 2 years ago, 59 views

  • Lavel 6.0
  • php7.3

I have translated the Larvel validation into Japanese, and it says, "Please enter half-width alphanumeric characters for name" as shown in the image.

Enter a description of the image here

"I would like to make this ""Please enter your account name in half-width alphanumeric characters."""
The original validation message is ":attribute should be half-width alphanumeric characters", so if you write "Please enter half-width alphanumeric characters for your account name" in solid form, the message will certainly be correct, but I cannot use other half-width alphanumeric characters.

Can I change the :attribute part in Japanese every time I use validation?

If there is a way, please let me know.

php laravel

2022-09-30 14:35

1 Answers

According to the documentation,

https://laravel.com/docs/6.x/validation#customizing-the-validation-attributes

If you would like the: attribute port of your validation message to be replaced with a custom attribute name, you may specify the custom names by overriding the attributes method. This method should return an array of attribute/name pairs:

So, why don't we override the following attributes method to the Requests class that we created?

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


2022-09-30 14:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.