Laravel语言上的Auth验证错误 [英] Laravel language on Auth validation error

查看:159
本文介绍了Laravel语言上的Auth验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用laravel默认功能来显示错误,但是要用另一种语言. 我不需要好名字",但需要翻译lang文件中的**:attribute 值. 现在,如果我只使用:

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

它工作得很好,因为:attribute 使用 phone 字段,并且使用的验证语言是:

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

推荐答案

真的很简单! 只需在语言文件中添加属性即可! 就我而言,对于lang/it/validation.php

Really simple! Just add attributes in the language file! In my case, for lang/it/validation.php

我刚刚设置:

'attributes' => [
    'phone' => 'telefono',
],

而句子的所有内容都保持不变

while all remain the same for the sentences

'required' => 'Il campo :attribute &grave; obbligatorio.',

这篇关于Laravel语言上的Auth验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆