验证流明数据中的密钥

时间:2018-07-05 21:08:14

标签: php laravel validation lumen

我正在验证如下所示的请求:

 {
  "data": [
    {
      "id": 1,
      "name": "Foo",     
      "values":{
        "val1":"This",
        "99":"That"
      }
    }
  ]
}

这是我的自定义消息:

$messages = [
     'data.id'=>'is required',
     'data.name'=>'is required',
     'data.values'=>'must be array',
     'data.values.*'=>'must be numeric'
];

我的验证规则是:

$this->validate(
            $request,
            [
                'data'=>'required|array',
                'data.*.id'=>'required|numeric',
                'data.*.name'=>'required',
                'data.*.values'=>'array',
                'data.*.values.*'=>'numeric'
             ],
            $messages
        );

该规则验证“值”数组中的值。我想改为验证“值”数组[val1,99]中的键。

1 个答案:

答案 0 :(得分:1)

using UnityEngine; using System.Collections; public class Mover : MonoBehaviour { public float speed; public new Rigidbody2D rigidbody; public bool random; void Start() { if (random) { rigidbody.velocity = Random.value * transform.right * speed; } else { rigidbody.velocity = transform.right * speed; } } } 编写自定义验证规则:

data.*.values