如果其他字段没有特定值,则为必填字段
问题描述:
如果account_name
字段不具有值“0”,那么我需要一个字段项目。我想要验证此方案在laravel如果其他字段没有特定值,则为必填字段
eg if account_name = '0' -project_name field is not required
if account_name = '1' - project_name field is required
$this->validate($request,[
'project_name'=>'required_without:account_name,0',
]);
答
尝试使用required_unless
!那么名称将是必需的,除非account_name等于0.