我正在使用邮递员向我的 Laravel API 发送一个发布请求。
{
"title" : "abc",
"body" : [
{"type":"paragraph","data":{"text":"aSADAd"}},
{"type":"header","data":{"text":"Heading......","level":2}},
{"type":"paragraph","data":{"text":"This is a para"}},
{"type":"list","data":{"style":"ordered","items":["ABC","XYZ"]}}
],
"status" : 1
}
body 字段是一个 JSON 数据字段 - 来自编辑器 js 的 JSON.stringify 输出。
我的 laravel 验证规则是 -
$validator = Validator::make($request->all(), [
'title' => 'required|string|max:255',
'body' => 'required|json',
'status' => 'required|boolean'
]);
但我收到这个错误 -
{
"validation_error": {
"body": [
"The body must be a valid JSON string."
]
}
}