如何在验证消息Laravel 5.2中获取数组索引 [英] How to get array index in validation message Laravel 5.2
本文介绍了如何在验证消息Laravel 5.2中获取数组索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将这些数组放入 Laravel Validator
作为参数:
These arrays I put into Laravel Validator
as arguments:
['item.*' => 'string'] // rules
['item.*.string' => 'Item number (index) is not string'] // messages
我想在验证消息中使用 index number
.上面的代码仅用于演示,不起作用.该怎么做?
I want to have index number
in validation message. Code above is just for demonstration and does not work. How to do this?
推荐答案
尝试或使用此方法
'name' : [ { 'value' : 'raju' } , { 'value' : 'rani'} ]
并通过
'name.*' or 'name.*.value' => 'required|string|min:5'
该消息将为
'name.*.required' => 'The :attribute is required'
'name.*.value.required' => 'The :attribute is required'
我认为这对您有帮助.
尝试这个,
public function messages()
{
$messages = [];
foreach ($this->request->get('name') as $key => $value){
$messages['name.'. $key .'.required'] = 'The item '. $key .' is not string';
}
return $messages;
}
这篇关于如何在验证消息Laravel 5.2中获取数组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文