Like a post
This commit is contained in:
@@ -170,4 +170,24 @@ class PostController extends AbstractController
|
|||||||
}
|
}
|
||||||
return $this->redirectToRoute('app_post_show', ['id' => $comment->getRelatedPost()->getId()]);
|
return $this->redirectToRoute('app_post_show', ['id' => $comment->getRelatedPost()->getId()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/post/{id}/like', name: 'app_posts', methods: ['POST'])]
|
||||||
|
#[IsGranted('ROLE_USER')]
|
||||||
|
public function addLike(Request $request, Post $post, EntityManagerInterface $entityManager, #[CurrentUser] User $user): Response
|
||||||
|
{
|
||||||
|
$user->addLikedPost($post);
|
||||||
|
$entityManager->flush();
|
||||||
|
return $this->redirectToRoute('app_post_show', ['id' => $post->getId()], Response::HTTP_SEE_OTHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/post/{id}/unlike', name: 'app_posts', methods: ['POST'])]
|
||||||
|
#[IsGranted('ROLE_USER')]
|
||||||
|
public function deleteLike(Request $request, Post $post, EntityManagerInterface $entityManager, #[CurrentUser] User $user): Response
|
||||||
|
{
|
||||||
|
$user->removeLikedPost($post);
|
||||||
|
$entityManager->flush();
|
||||||
|
return $this->redirectToRoute('app_post_show', ['id' => $post->getId()], Response::HTTP_SEE_OTHER);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@
|
|||||||
<p class="card-text">{{ post.commentary }}</p>
|
<p class="card-text">{{ post.commentary }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
28 ❤️
|
{{ post.likes.count() }} ❤️
|
||||||
{{ post.comments.count() }} 💬
|
{{ post.comments.count() }} 💬
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user