我很好奇,为什么我的资源响应没有包含在data
:
这是我的资源:
App\Http\Resources\CategoryResource Object
(
[resource] => stdClass Object
(
[id] => 12
[title] => Category
[description] => <p>Test</p>
[with] => Array
(
)
[additional] => Array
(
)
)
一旦像这样返回此资源:
$response = $this->client->getApiResponse('/api/category/'.$id); //response comes from third-party-API
$data = new CategoryResource(json_decode ($response->getContents())->data);
return response()->json($data);
输出是
{
"id": 12,
"title": "Category",
"description": "<p>Test</p>"
}
但根据https://laravel.com/docs/5.8/eloquent-resources#data-wrapping它应该是:
{
"data": {
"id": 12,
"title": "Category",
"description": "<p>Test</p>"
}
}
为什么data
这里缺少-wrapper?