In Laravel 9, when there are 2 sets of time fields, each group is 2, one is the beginning and the other is the end, and the verification must have an implementation of a set of time fields
1. In a list page, when there are 2 sets of time fields, each group is 2, one is the beginning and the other is the end, and it is necessary to verify that there must be a set of time fields. as shown in Figure 1
2. A total of 4 fields are: shipping_at_gmt_start, shipping_at_gmt_end, operated_at_gmt_start, operated_at_gmt_end. There must be a set of time fields, both Shipping_AT_GMT_START, SHIPPING_AT_GMT_END . Or there must be OPERATED_AT_GMT_START, OPERATED_AT_GMT_END
3. The final verification rule is implemented as follows, relying on the required_without implementation. When one of the Shipping_at_GMT_Start and SHIPPING_AT_GMT_END does not exist, then Operated_at_gmt_start is required. in line with expectations. as shown in Figure 2
public function validateIndex(array $params): ValidationValidator
{
$validator = Validator::make(
$params,
[
'filter.shipping_at_gmt_start' => 'required_without:filter.operated_at_gmt_start,filter.operated_at_gmt_end|date',
'filter.shipping_at_gmt_end' => [
'date',
'after_or_equal:filter.shipping_at_gmt_start',
function ($attribute, $value, $fail) use ($params) {
$startDate = Carbon::parse($params['filter']['shipping_at_gmt_start'])->addMonths(3);
$endDate = Carbon::parse($value);
if ($endDate->isAfter($startDate)) {
$fail('交运时间结束与交运时间开始的跨度不可超过3个月');
}
},
],
'filter.operated_at_gmt_start' => 'required_without:filter.shipping_at_gmt_start,filter.shipping_at_gmt_end|date',
'filter.operated_at_gmt_end' => [
'date',
'after_or_equal:filter.operated_at_gmt_start',
function ($attribute, $value, $fail) use ($params) {
$startDate = Carbon::parse($params['filter']['operated_at_gmt_start'])->addMonths(3);
$endDate = Carbon::parse($value);
if ($endDate->isAfter($startDate)) {
$fail('操作时间结束与操作时间开始的跨度不可超过3个月');
}
},
],
],
[
'filter.shipping_at_gmt_start.required_without' => '时间筛选必填',
'filter.shipping_at_gmt_start.date' => '交运时间开始必须是日期',
'filter.shipping_at_gmt_end.date' => '交运时间结束必须是日期',
'filter.shipping_at_gmt_end.after_or_equal' => '交运时间结束必须晚于或等于交运时间开始',
'filter.operated_at_gmt_start.required_without' => '时间筛选必填',
'filter.operated_at_gmt_start.date' => '操作时间开始必须是日期',
'filter.operated_at_gmt_end.date' => '操作时间结束必须是日期',
'filter.operated_at_gmt_end.after_or_equal' => '操作时间结束必须晚于或等于操作时间开始'
]
);
if ($validator->stopOnFirstFailure()->fails()) {
throw new BusinessException(BusinessException::MODULE_ORDER, $validator->getMessageBag()->first());
}
return $validator;
}
4. When both Shipping_AT_GMT_START and SHIPPING_AT_GMT_END do not exist, then OPERATED_AT_GMT_START is required. in line with expectations. as shown in Figure 3
5. Conversely, another group of fields also conforms to the verification results of steps 3 and 4.


