[英]Validate value where another column's value for the record is in array of values
要验证的输入是一棵树,其中子类别有效,仅当其父类别也已选择时也是如此。
输入值如下:
$categories = [1,2,3];
//in database, each subcategory has column "category_id"
$sub_categories = [4,5,6]
验证方式
$this->validate([
"sub_categories.*" => [
"exists:sub_categories,id",
//Rule for checking that the category_id for this subcategory
//exists in the categories array.
]
])
是否有内置的laravel规则,或者我需要自己编写规则?
使用Rule
类
Validation
$this->validate([
"sub_categories.*" => [
"exists:sub_categories,id",
\Illuminate\Validation\Rule::in($categories),
],
])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.