laravel 中的表单请求嵌套数组
form request nestead array in laravel
我正在使用 Laravel 并且我有一个分类系统,我想使用表单请求来验证它
所以请求是这样的
array:5 [▼
"type" => "product"
"minprice" => "10"
"maxprice" => "10000000000"
"color" => null
"sortBy" => array:2 [▼
"field" => "created_at"
"orderBy" => "desc"
]
]
我想检查 'field' 和 'orderBy' 是否只有 created_at 值和描述值
我该怎么做?
这是我的表单请求
return [
'type' => 'required|in:all,file,service,product',
'minprice' => 'required|numeric|min:0|max:1000000000000',
'maxprice' => 'required|numeric|min:0|max:100000000000000',
'color' => 'min:0|max:7',
// 'sortBy' => 'in:desc,orderBy',
];
阅读文档:https://laravel.com/docs/6.x/validation
它说:
If your HTTP request contains "nested" parameters, you may specify them in your validation rules using "dot" syntax:
所以你可以使用:
'sortBy.field' => 'in:created_at,updated_at,deleted_at',
'sortBy.orderBy' => 'in:asc,desc',
我正在使用 Laravel 并且我有一个分类系统,我想使用表单请求来验证它
所以请求是这样的
array:5 [▼
"type" => "product"
"minprice" => "10"
"maxprice" => "10000000000"
"color" => null
"sortBy" => array:2 [▼
"field" => "created_at"
"orderBy" => "desc"
]
]
我想检查 'field' 和 'orderBy' 是否只有 created_at 值和描述值
我该怎么做?
这是我的表单请求
return [
'type' => 'required|in:all,file,service,product',
'minprice' => 'required|numeric|min:0|max:1000000000000',
'maxprice' => 'required|numeric|min:0|max:100000000000000',
'color' => 'min:0|max:7',
// 'sortBy' => 'in:desc,orderBy',
];
阅读文档:https://laravel.com/docs/6.x/validation
它说:
If your HTTP request contains "nested" parameters, you may specify them in your validation rules using "dot" syntax:
所以你可以使用:
'sortBy.field' => 'in:created_at,updated_at,deleted_at',
'sortBy.orderBy' => 'in:asc,desc',