Laravel translate required_if values

I am using Laravel version 5.2.45. I currently have some problems translating the required_if rule. When I use the required_if field, its value prints the field value in the error message, which in this case is 1 or 0. This is not very readable.

For instance:

Field 1 is required if type 0

I would like to:

Field 1 is required if the default type

Is there a way to translate the values ​​of a rquired_if /: value to a value?

Controller:

$customerVal = Validator::make($request->all(), [
        'field1' => 'required_if:type,0',
        'field2' => 'required_if:type,0',
    ]);

View:

@if (count($errors) > 0)
        <div class="modalMsg alert">
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif

I see that Laravel has this in the language section:

'required_if'          => ':attribute is required when :other are  :value.',

So this is basically: the value I need to translate (dynamically). I tried below, but this does not replace 0:

'attributes' => [
'field1' => [
            '0' => 'test'
        ]
]
+4
source share
1 answer

, .

app/lang/en/validation.php :

'values' => [
    'type' => [
        '0' => 'default',
     ],
 ],

laravel github.

+1

Source: https://habr.com/ru/post/1669273/


All Articles