首页 > 解决方案 > Laravel APi 资源 whenLoaded

问题描述

我正在尝试使用 whenLoaded 加载模型关系,如下所示:

庭院资源

'latest_inspection' => new Inspection($this->whenLoaded('latestInspection'))

哪个工作正常,但是在检查资源上还有一些其他关系没有被包括在内:

检验资源

'completed_tasks' => TaskResource::collection($this->whenLoaded('tasks')),
'feedings' => FeedResource::collection($this->whenLoaded('feeds')),

如何确保这些也加载到 Yard 资源的 latestInspection 中?

标签: laravellaravel-5

解决方案


推荐阅读