Laravel 验证:两个链条条件

Laravel validation: two chain conditions

我有四个文本框(textbox_1、textbox_2、textbox_3、textbox_4)。

如果 textbox_4 为空,我需要检查 textbox_2 和 textbox_3 是否不为空,然后我需要要求 textbox_1 不为空。

请帮我在 App\Http\Request\MyFormRequests.php

里面做这个

请无视,已解决:

$rules = [ 'previous_fields' => 'require' ];

if ($this->textbox_4 =='')
{
   $rules['textbox_1'] = 'required_with_all:textbox_2,textbox_3';
}

return $rules;

您可以为此使用 required_without_all。检查 official Laravel documentation.

来自文档:

The field under validation must be present only when all of the other specified fields are not present.