Php 在laravel验证中,26个字段中至少需要1个字段
我想在拉拉维尔开一张收据。我有26个输入字段。很难用条件逐一声明验证。是否可以指定至少1个字段?请帮忙Php 在laravel验证中,26个字段中至少需要1个字段,php,laravel,validation,Php,Laravel,Validation,我想在拉拉维尔开一张收据。我有26个输入字段。很难用条件逐一声明验证。是否可以指定至少1个字段?请帮忙 $rules = [ 'a_field' => 'required_without_all:b_field,c_field', 'b_field' => 'required_without_all:a_field,c_field', 'c_field' => 'required_without_all:a_field,b_field', ]; $mes
$rules = [
'a_field' => 'required_without_all:b_field,c_field',
'b_field' => 'required_without_all:a_field,c_field',
'c_field' => 'required_without_all:a_field,b_field',
];
$message = [
'a_field' => 'The a is required when none of other fields are present.',
'b_field' => 'The b is required when none of other fields are present.',
'c_field' => 'The c is required when none of other fields are present.',
];
输入太多
$fields = collect(['a', 'b', 'c', 'd', 'e']);
$rules = $fields->mapWithKeys(function ($field) use ($fields) {
return [
$field => 'required_without_all:' . $fields->reject(function ($item) use ($field) {
return $item == $field;
})->implode(',')
];
})->toArray();
输入太多
$fields = collect(['a', 'b', 'c', 'd', 'e']);
$rules = $fields->mapWithKeys(function ($field) use ($fields) {
return [
$field => 'required_without_all:' . $fields->reject(function ($item) use ($field) {
return $item == $field;
})->implode(',')
];
})->toArray();
我是否需要为此验证添加26行?还有其他最短的路吗?像使用数组或其他什么?这对你有帮助吗?我不知道设计自定义规则。。你能告诉我如何在验证中定义这个方法吗。拜托?这不是自定义规则我总是用这个代码<代码>$this->validate($request,['field'=>'required',])代码>是否需要为此验证添加26行?还有其他最短的路吗?像使用数组或其他什么?这对你有帮助吗?我不知道设计自定义规则。。你能告诉我如何在验证中定义这个方法吗。拜托?这不是自定义规则我总是用这个代码<代码>$this->validate($request,['field'=>'required',])代码>