【发布时间】:2019-11-28 18:05:06
【问题描述】:
我正在使用 {json:api} Client 将 json 解析为 Eloquent 类模型。
我有两个模型,Congress 和 Speaker。一个Congress 有很多Speaker。
这是我能够做到的:
$repository = app(App\Repositories\CongressRepository::class);
$document = $repository->all();
$document 是具有以下属性的CollectionDocument:
我想获得第一个Congress 的speakers。这是我尝试过的
$congresses = $document->getData();
$congress = $congresses->first();
$congress->speakers // <- this is null!
为什么$congress->speakers 为空?我也试过给我们$repository->all(['includes' => 'speakers']);
但这没有区别。
【问题讨论】: