我的刀片中有一个有3个输入的表单。用户必须至少填写其中一个输入,我的意思是,如果其他输入为空,则每个输入都是必需的。我不知道如何在Laravel控制器中编写我的验证规则。输入:
<div class="mt-3">
<x-label for="telegram" value="__('Telegram')"/>
<x-input
type="text" name="telegram"
class="mt-1 block w-full"
autofocus/>
</div>
<div class="mt-3">
<x-label for="whatsapp" value="__('Whatsapp')"/>
<x-input
type="text" name="whatsapp"
class="mt-1 block w-full"
autofocus/>
</div>
<div class="mt-3">
<x-label for="discord" value="__('Discord')"/>
<x-input
type="text" name="discord"
class="mt-1 block w-full"
autofocus/>
</div>发布于 2021-09-14 14:18:36
在您控制器中,您可以验证请求并使用required_without_all规则。
required_without_all:foo,bar,...
The field under validation must be present and not empty only when all of the other specified fields are empty or not present.$validated = $request->validate([
'telegram' => 'required_without_all:whatsapp,discord',
'whatsapp' => 'required_without_all:telegram,discord',
'discord' => 'required_without_all:telegram,whatsapp',
]);https://stackoverflow.com/questions/69179346
复制相似问题