Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 如何加载与{json:api}客户端的关系?_Laravel_Json Api - Fatal编程技术网

Laravel 如何加载与{json:api}客户端的关系?

Laravel 如何加载与{json:api}客户端的关系?,laravel,json-api,Laravel,Json Api,我正在使用语法将json解析为雄辩的模型 我有两种型号,Congress和Speaker。一个大会有许多演讲者 这就是我能够做到的: $repository = app(App\Repositories\CongressRepository::class); $document = $repository->all(); $document是具有以下属性的集合文档: 我想请第一届大会的演讲者。这就是我试过的 $congresses = $document->getData();

我正在使用语法将json解析为雄辩的模型

我有两种型号,
Congress
Speaker
。一个
大会
有许多
演讲者

这就是我能够做到的:

$repository = app(App\Repositories\CongressRepository::class);
$document = $repository->all();
$document
是具有以下属性的
集合文档

我想请第一届
大会的
演讲者
。这就是我试过的

$congresses = $document->getData();
$congress = $congresses->first();
$congress->speakers // <- this is null!
$congressions=$document->getData();
$congressions=$congressions->first();
$congress->speakers//speakers
null?我还试着告诉我们
$repository->all(['includes'=>'speakers'])

但这没有区别

似乎
$congress->speakers
为空,因为关系为空:

我使用包创建
json
输出。在
Schema.php
中,我必须添加
self::DATA
以使数据可见,如中所述

我仍然想知道,如果
API
中只给出了
链接,是否可以加载该关系

public function getRelationships($resource, $isPrimary, array $includeRelationships)
{
    return [
        'speakers' => [
            self::SHOW_SELF => true,
            self::SHOW_RELATED => true,
            self::DATA => function () use ($resource) {
                return $resource->speakers;
            },
        ],
    ];
}