gpt4 book ai didi

php - Laravel 验证 : validate field only if another is present

转载 作者:行者123 更新时间:2023-12-03 18:38:27 25 4
gpt4 key购买 nike

我想仅在存在“needs_login”时验证“account_id”。我这样做了:

$rules = [
'account_id' => ['required_with:needs_login','custom_validation']
];

但它不起作用,因为如果 Needs_login 字段不存在但 account_id 有一些值,那么它会尝试执行“custom_validation”。
我也试图把“有时”参数
$rules = [
'account_id' => ['required_with:needs_login', 'sometimes', 'custom_validation']
];

但它没有用。

有任何想法吗?

P.S.: Remember that I wanted to validate the account_id only if needs_login is present, not to check if account_id is present if needs_login does.

最佳答案

你试过required_if吗?

$rules = [
'account_id' => ['required_if:needs_login,1']
];

关于php - Laravel 验证 : validate field only if another is present,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33106512/

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