K
K
Konstantin Eliseev2019-01-24 17:07:20
Laravel
Konstantin Eliseev, 2019-01-24 17:07:20

Is it possible to specify different translations for different validation rules in Laravel?

Tell me - is it possible to specify different translations for different files with validation. Those. if, for example, both will have the expires_at field, but in 1, for example, it will refer to the user, and in the other to the ad?
Now translations are stored in the resources/lang/ru/validation.php file

<?php
return [

    'before_or_equal' => 'В поле :attribute должна быть дата не позднее :date.',
    //...
    'required' => 'Поле :attribute обязательно для заполнения.',
    //...

    'custom' => [
        'expires_at' => [
            'required' => 'Поле Дата окончания объявления обязательно для заполнения.',
            'before_or_equal' => 'В поле Дата окончания объявления должна быть дата не позднее 5 дней от текущей',
        ]
    ],
];

Validation file app/Http/Requests/CreateRequest.php
class CreateRequest extends FormRequest
{
//..
    public function rules(): array
    {
        return [
            'expires_at' => 'required|date|date_format:d-m-Y|after:today|before_or_equal:+' . Warehouse::PUBLICATION_PERIOD .' days',
        ];
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2019-01-24
@K0r5hun

https://laravel.com/docs/5.7/validation#custom-err...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question