返回一个Laravel资源的查询一直返回500错误。
<p>我正在尝试构建一个包含详细信息的数组,以传递给仪表板资源,但在尝试将数据传递给资源时遇到了一些问题。<br /><br />在我的控制器中,我正在构建查询,如下所示:<br /></p>
<pre class="lang-php prettyprint-override"><code>$user = auth()->user();
$teams = Team::query()
->where('user_id', $user->id)
->get();
$jobs = Job::query()
->where('user_id', $user->id)
->get();
return new DashboardResource($user, $jobs, $teams);
</code></pre>
<p>然后再资源中</p>
<pre class="lang-php prettyprint-override"><code>public function toArray(Request $request): array
{
return [
'name' => $user->name,
'teams' => TeamResource::collection($this->teams),
'jobs' => JobResource::collection($this->jobs),
];
}
</code></pre>
<p>我一直遇到一个问题,就是;</p>
<pre class="brush:php;toolbar:false;">Property [jobs] does not exist on this collection instance.</pre>
<p>我觉得我可能做得很不对。</p>