我一直在 laravel 中至少使用一个 required_without_all 字段。
这是我的规则代码
'rental_company_id' => 'required_without_all:camper_id,take_over_station_id,returnable_station_id',
'camper_id' => 'required_without_all:rental_company_id,take_over_station_id,returnable_station_id',
'take_over_station_id' => 'required_without_all:rental_company_id,camper_id,returnable_station_id',
'returnable_station_id' => 'required_without_all:rental_company_id,camper_id,take_over_station_id',
这是我的自定义消息,它将覆盖 laravel 生成的默认消息
'rental_company_id.required_without_all' => 'The Rental Companies is required when none of Campers, Takeover stations and Returnable stations are present.',
'camper_id.required_without_all' => 'The Campers is required when none of Rental Companies, Takeover stations and Returnable stations are present.',
'take_over_station_id.required_without_all' => 'The Takeover stations is required when none of Campers, Rental Companies and Returnable stations are present.',
'returnable_station_id.required_without_all' => 'The Returnable stations is required when none of Campers, Rental Companies and Takeover stations are present.',
而不是向用户显示多行错误消息。有什么方法可以将这四条消息总结成一条消息,例如
以下季节之一,租赁公司...必须在场。
提前致谢。