src/PHPDish/Bundle/ForumBundle/Controller/TopicController.php
public function toggleVoterAction($id)
    {
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');

        $topic = $this->getTopicManager()->findTopicById($id);
        if (!$topic) {
            throw new \InvalidArgumentException($this->get('translator')->trans('topic.not_exists'));
        }
        if ($isVoted = $topic->isVotedBy($this->getUser())) {
            $this->getTopicManager()->removeVoter($topic, $this->getUser());
        } else {
            $this->getTopicManager()->addVoter($topic, $this->getUser());
        }
        return $this->json([
            'vote_count' => $topic->getVoteCount(),
            'is_voted' => !$isVoted
        ]);
    }
public function toggleVoterAction($id)
    {
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');

        $topic = $this->getTopicManager()->findTopicById($id);
        if (!$topic) {
            throw new \InvalidArgumentException($this->get('translator')->trans('topic.not_exists'));
        }
        if ($isVoted = $topic->isVotedBy($this->getUser())) {
            $this->getTopicManager()->removeVoter($topic, $this->getUser());
        } else {
            $this->getTopicManager()->addVoter($topic, $this->getUser());
        }
        return $this->json([
            'vote_count' => $topic->getVoteCount(),
            'is_voted' => !$isVoted
        ]);
    }
切换点赞状态

@Route("/topics/{id}/voters", name="topic_toggle_voter", methods={"POST"})