我正在使用{json:api} Client将json解析为Eloquent相似的模型。
我有两个模型,Congress
和Speaker
。 Congress
有很多Speaker
。
这是我能够做到的:
$repository = app(App\Repositories\CongressRepository::class);
$document = $repository->all();
[$document
是具有以下属性的CollectionDocument
:
我想获得第一个speakers
的Congress
。这是我尝试过的
$congresses = $document->getData();
$congress = $congresses->first();
$congress->speakers // <- this is null!
为什么$congress->speakers
为空?我也尝试过给我们$repository->all(['includes' => 'speakers']);
但这没有区别。
基于文档关系应加载方法调用。
$congress->speakers();