如何在流明中验证请求json

时间:2018-11-18 06:27:03

标签: php lumen

如何在流明中请求json? 我有这样的要求json:

{ 
    account : {"id" : "1", "username" : "dummy1", "password":"1234"},
    information : {"realName":"Dummy 1", "age" : 20, "bod":"dd-mm-yyyy"}
}

我在控制器中尝试过这样:

$formData = $request->json()->all();
$data = array_merge($formData['user'], $formData['profile']);
$validator = $this->validate($data, [
    "id" => "required",
    "username" => "required",
    "realName" => "required",
    // etc rules
]);

但是我总是会遇到这样的错误:

  

传递给Laravel \ Lumen \ Routing \ Controller :: validate()的参数1必须是Illuminate \ Http \ Request的实例,给定数组,

请帮助解决我的问题, 任何帮助将不胜感激

谢谢

0 个答案:

没有答案