public function map(EntityContract $entity, array $data) { $entity->init((object) $data); $id = $data['ID']; $entity->setPosts(function () use($id) { return $this->postRepository->postsByAuthor($id); }); $entity->setPages(function () use($id) { return $this->pageRepository->pagesByAuthor($id); }); $entity->setComments(function () use($id) { return $this->commentRepository->commentsByAuthor($id); }); }