【发布时间】:2018-01-03 01:34:02
【问题描述】:
$rules = [
'user_id' => 'required|exists:users,id',
'preparat_id' => 'required|exists:preparats,id',
'zoom' => 'required|numeric',
'comment' => '',
'type' => 'in:' . Annotation::ANN_RECTANGLE . ',' . Annotation::ANN_CIRCLE . ',' . Annotation::ANN_POLYGON . ',' . Annotation::ANN_PIN,
'point_x' => 'array|required|numeric',
'point_y' => 'array|required|numeric',
];
$this->validate($request, $rules);
point_x 和 point_y 是一个数组输入。
我的规则是:
point_x 和 point_y 必须存在。
我如何发送数据:
- point_x[0] = 123;
- point_y[0] = 123;
是的
- point_x[0] = 123;
- point_y[0] = 123;
- point_x[1] = 123;
- point_y[1] = 123;
- point_x[2] = 123;
- point_y[2] = 123;
是的
point_x[0] = 123; point_y[0] = "SO";
错误
point_y[0] = 123;
错误
- point_x[0] = 123;
- point_y[0] = 123;
- point_x[1] = 123;
- point_y[1] = "Taadaa";
- point_x[2] = 123;
- point_y[2] = 123;
错误
我的 Laravel 版本是 5.4
我应该如何像上面那样编写检查规则。我试过数组参数,但它不起作用。
【问题讨论】:
-
我在这里解决了一个类似的问题:stackoverflow.com/questions/44715505/…
标签: php arrays laravel validation