我正在尝试使用“language > {language} > validation.php”中的验证属性,将 :attribute name (input name) 替换为正确的可读名称(例如:first_name > First name)。使用起来似乎很简单,但验证器没有显示“好名字”。
我有这个:
'attributes' => array(
'first_name' => 'voornaam'
, 'first name' => 'voornaam'
, 'firstname' => 'voornaam'
);
为了显示错误:
@if($errors->has())
<ul>
@foreach ($errors->all() as $error)
<li class="help-inline errorColor">{{ $error }}</li>
@endforeach
</ul>
@endif
以及控制器中的验证:
$validation = Validator::make($input, $rules, $messages);
$messages 数组:
$messages = array(
'required' => ':attribute is verplicht.'
, 'email' => ':attribute is geen geldig e-mail adres.'
, 'min' => ':attribute moet minimaal :min karakters bevatten.'
, 'numeric' => ':attribute mag alleen cijfers bevatten.'
, 'url' => ':attribute moet een valide url zijn.'
, 'unique' => ':attribute moet uniek zijn.'
, 'max' => ':attribute mag maximaal :max zijn.'
, 'mimes' => ':attribute moet een :mimes bestand zijn.'
, 'numeric' => ':attribute is geen geldig getal.'
, 'size' => ':attribute is te groot of bevat te veel karakters.'
);
有人可以告诉我我做错了什么。我希望 :attribute 名称被属性数组(语言)中的“好名字”替换。
谢谢!
编辑:
我注意到问题是我从未为我的 Laravel 项目设置默认语言。当我将语言设置为“NL”时,上面的代码有效。但是,当我设置我的语言时,该语言将出现在 url 中。我更喜欢它没有。
所以我的下一个问题是:是否可以从 url 中删除语言,或者设置默认语言,使其不出现在那里?