S
S
suhuxa12017-09-20 21:17:28
Laravel
suhuxa1, 2017-09-20 21:17:28

How to set a name in Russian for each field in laravel during validation?

Hey!
I'm validating the fields, and started adding my posts in the style:
The :attribute field is required!
Unfortunately, instead of :attribute, the name of the field is substituted, and as a result, the view will be something like this:
The name field is required!
How to add Russian field names instead of :attribute so that it says: "Field "Name" is empty". The Last Name field is empty. ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Melikhov, 2017-09-20
@amelihovv

One of the validator arguments is $attributes, an array with custom attribute names.

\Validator::make($data, $rules, $messages, [
     'name' => 'имя',
 ]);

This can be done globally in resources/lang/en/validation.php using the attributes key.
If you use FormRequest for validation, then you can override the attributes method in it
public function attributes()
{
  return ['name' => 'имя'];
}

A
Alexander Aksentiev, 2017-09-20
@Sanasol

I didn’t personally google about Russian, but you can do it like this

$validator = \Validator::make([
            'filters' => $filters,
        ], [
            'filters.filters.date_from.value' => 'bail|required|date',
            'filters.filters.date_to.value' => 'bail|required|date',
        ], [
            'filters.filters.date_from.value.required' => 'Укажите дату начала',
            'filters.filters.date_from.value.date' => 'Укажите корректную дату начала',
            'filters.filters.date_to.value.required' => 'Укажите дату конца',
            'filters.filters.date_to.value.date' => 'Укажите корректную дату конца',
        ]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question