public function create(User $user, $postId) { $post = $this->postRepository->find($postId); $postVote = new PostVote(); $postVote->setPost($post); $postVote->setUser($user); $postVote->setCreatedAt(new \DateTime()); $postVote = $this->repository->create($postVote); $this->postRepository->updateTotalVotes($post); return $postVote; }
/** * Remove vote * * @param \AppBundle\Entity\PostVote $vote */ public function removeVote(\AppBundle\Entity\PostVote $vote) { $this->votes->removeElement($vote); }