我想仅在存在“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/