gpt4 book ai didi

laravel - 验证 Laravel 验证中的两个字段

转载 作者:行者123 更新时间:2023-12-02 16:30:04 24 4
gpt4 key购买 nike

我有 2 个字段要检查验证...

parent
tag

我想要这样的东西:

if(parent == 0)
return 'tag is required';
else
return 'tag can be nullable';

我尝试了这样的事情,但这是错误的:

'parent' => 'nullable|numeric',
'tags' => 'required_with:parent=0|array|max:8',

最佳答案

使用required_if规则。

The field under validation must be present and not empty if the anotherfield field is equal to any value.

'parent' => 'nullable|numeric',
'tags' => 'required_if:parent,0|array|max:8',

https://laravel.com/docs/5.5/validation#rule-required-if

关于laravel - 验证 Laravel 验证中的两个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47996750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com