如何获取验证消息中的数组索引 Laravel 5.2
How to get array index in validation message Laravel 5.2
我将这些数组作为参数放入 Laravel Validator
:
['item.*' => 'string'] // rules
['item.*.string' => 'Item number (index) is not string'] // messages
我想在验证消息中包含 index number
。上面的代码只是为了演示,并不起作用。如何做到这一点?
试试这个或使用这个
'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 Validator
:
['item.*' => 'string'] // rules
['item.*.string' => 'Item number (index) is not string'] // messages
我想在验证消息中包含 index number
。上面的代码只是为了演示,并不起作用。如何做到这一点?
试试这个或使用这个
'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;
}