当验证器属性为数组时,如何翻译键?
例如:
这是带有数组
'image.author'
和 'image.book'
的验证器。
$validator = Validator::make($request->all(), [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
'image.author' => 'required',
'image.book' => 'required',
]);
在
validation.php
上存在这些属性。
'attributes' => [
'image.author' => 'image of author',
'image.book' => 'image of book',
],
如果我使用tinker来调试:
__('validation.attributes.image.author');
“验证.属性.图像.作者”
输出正确应该是:
“作者形象”
“author”和“book”应该是验证属性数组中“images”索引的索引。
'attributes' => [
'image' => [
'author' => 'image of author',
'book' => 'image of book',
],
],
我能够翻译这些的唯一方法是:
trans('validation.attributes')['image.author']; //'image of author'
trans('validation.attributes')['image.book']; //'image of book'
trans('validation.attributes')
返回包含所有键的数组。