[英]Laravel form validation if or rules
i have one form which has 4 text fields.我有一个包含 4 个文本字段的表单。 I want Laravel to check if the fields are field, but it does not need to check all of them, just only two of them.
我希望 Laravel 检查字段是否为字段,但不需要检查所有字段,只需检查其中两个。
Example: field1, field2, field3, field4.示例:field1、field2、field3、field4。 To complete the form the user must enter values for field1 and field2 or for field3 and field4.
要完成表单,用户必须输入 field1 和 field2 或 field3 和 field4 的值。
Is this possible ?这可能吗 ?
i will post the answer if somebody needs it in future.如果将来有人需要,我会发布答案。 I have one field (price), which is always required.
我有一个字段(价格),这始终是必需的。 Than i have three additional fields where the combination field (volume) or fields (buy, sell) is also required.
比我还有三个额外的字段,其中还需要组合字段(交易量)或字段(买、卖)。
Here is the solution:这是解决方案:
return [
'price' => ['required'],
'volume' => ['required_without_all:buy,sell'],
'buy' => ['required_without:volume'],
'sell' => ['required_without:volume'],
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.