*/ private array $progressByGoalId; /** * @param array $progressByGoalId */ public function __construct($resource, array $progressByGoalId) { parent::__construct($resource); $this->progressByGoalId = $progressByGoalId; } protected function collects(): ?string { return null; } /** * Transform the resource collection into an array. * * @return array>>> */ public function toArray(Request $request): array { return $this->collection->map(function (Goal $goal) use ($request): array { return (new GoalResource($goal, $this->progressByGoalId[$goal->getKey()])) ->toArray($request); })->all(); } }