I'm trying to build an array of details to pass to a dashboard resource, but I'm having some issues trying to pass the data to the resource.
In my controller I am building the query like this:
$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);
Then go to the resource
public function toArray(Request $request): array { return [ 'name' => $user->name, 'teams' => TeamResource::collection($this->teams), 'jobs' => JobResource::collection($this->jobs), ]; }
I have been encountering a problem, that is;
Property [jobs] does not exist on this collection instance.
I think I may have done something wrong.
The JsonResource constructor only accepts one parameter. You should create an association between Teams and Jobs in the user model, and then call $user->teams and $user->jobs in the resource.