覆盖 required_without_all laravel 的单个消息

Bib*_*kya 2 php laravel

我一直在 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',
Run Code Online (Sandbox Code Playgroud)

这是我的自定义消息,它将覆盖 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.',
Run Code Online (Sandbox Code Playgroud)

而不是向用户显示多行错误消息。有什么方法可以将这四条消息总结成一条消息,例如

以下季节之一,租赁公司...必须在场。

提前致谢。

SAS*_*ASM 5

有一个非常简单的方法可以实现这一目标。将规则应用于虚构ids字段,然后包括您希望在之后应用验证的所有实际字段required_without_all。并且只有一条相应的验证消息。

$validator = Validator::make($request->all(), [
            'ids' => 'required_without_all:rental_company_id,camper_id,take_over_station_id, returnable_station_id'
            ], [
            'required_without_all' => 'One of the following Season,Rental companies,... must be present.'
            ]);
Run Code Online (Sandbox Code Playgroud)