问题
I would like to use the laravel default functionality to show the error, but in another language. I don't need a "nice name", but a translation for the **:attribute value in lang files. Right now if I just use:
<input type="text" placeholder="{{ trans('generic.phone') }}" name="phone" value="{{ old('phone') }}">
@if ($errors->has('phone'))
<span class="help-block">
<strong>{{ $errors->first('phone') }}</strong>
</span>
@endif
it works perfectly, because the :attribute takes the field phone, and in the validation language I have:
'required' => 'The :attribute field is required.',
But how to manage phone field with a language file?
Do I must have to write a custom error for each field? Please tell me I don't.
The following function is just a wrong example to let you understand what I'm trying to do
@if ($errors->has('phone'))
<strong>{{ $errors->first(trans('generic.phone')) }}</strong>
@endif
回答1:
Really simple!
Just add attributes in the language file!
In my case, for lang/it/validation.php
I just set:
'attributes' => [
'phone' => 'telefono',
],
while all remain the same for the sentences
'required' => 'Il campo :attribute ` obbligatorio.',
来源:https://stackoverflow.com/questions/41897327/laravel-language-on-auth-validation-error