要验证的输入是一棵子类别有效的树,仅当其父类别也已选择时。
输入值如下:
$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规则,或者我需要自己编写规则?
答案 0 :(得分:0)
使用Rule
类
Validation
$this->validate([
"sub_categories.*" => [
"exists:sub_categories,id",
\Illuminate\Validation\Rule::in($categories),
],
])