gpt4 book ai didi

php - Laravel 数组验证

转载 作者:搜寻专家 更新时间:2023-10-31 20:59:59 26 4
gpt4 key购买 nike

$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_xpoint_y 是数组输入。

我的规则是:

point_xpoint_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] = "所以";

错误


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

我应该如何写一个像上面那样的检查规则。我尝试了数组参数,但它不起作用。

最佳答案

仅尝试遵循数组 point_xpoint_y 的规则,

$this->validate($request, [
'point_x' => 'required',
'point_y' => 'required',
'point_x.*' => 'numeric',
'point_y.*' => 'numeric',
],
$messages = [

]
);

参见文档 Array Input Validation

关于php - Laravel 数组验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45348791/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com