在使用contentful laravel sdk时,set include不会获取属于我获取的条目的任何资产。下面的代码(我的):
public function index()
{
$query = $this->query
->setContentType('gallery')
->setInclude(10);
$entry = $this->client->getEntries($query);
if (!$entry) {
abort(404);
}
$data = ['galleries' => $entry];
return view('welcome', ['data' => $data]);
}有争议的例子:
// contentful.php 3.0
$client = new Contentful\Delivery\Client(
'<content_delivery_api_key>',
'<space_id>',
'<environment_id>' // Defaults to "master" if ommitted
);
$query = (new Contentful\Delivery\Query())
->setInclude(2);
$entries = $client->getEntries($query);我的结果:
[

]
我希望previewImage和图像数组包含包含文件位置的“字段”。我只得到'sys‘。我不明白为什么include没有获取这些数据。如果我将setInclude设置为20,超过了限制,我会得到一个错误。下面

我应该采取不同的做法吗?我在javascript前端项目中获得了预期的结果,但是使用laravel我什么也得不到。
发布于 2018-07-27 20:01:13
include实际上工作得很好。在内部,链接的条目/资产使用Link对象表示,一旦您访问该字段,该对象就会解析为实际的条目/资产(在本例中,这是通过$entry->getPreviewImage()完成的,它将返回在前面的查询中加载的Asset对象)。
这意味着,如果您转储条目,您将不会在previewImage字段中看到您期望的实际对象,但如果在常规使用中,一切都将正常工作。
https://stackoverflow.com/questions/50747858
复制相似问题