Answer the question
In order to leave comments, you need to log in
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 дней от текущей',
]
],
];
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question