- public function getComments($pageId, $commentId = null) {
- try {
- $page = $this->entityRepo->getById('page', $pageId, true);
- } catch (ModelNotFoundException $e) {
- return response('Not found', 404);
- }
-
- if($page->draft) {
- // cannot add comments to drafts.
- return response()->json([
- 'status' => 'error',
- 'message' => trans('errors.no_comments_for_draft'),
- ], 400);
- }
-
- $this->checkOwnablePermission('page-view', $page);
-
- $comments = $this->commentRepo->getCommentsForPage($pageId, $commentId);
- if (empty($commentId)) {
- // requesting for parent level comments, send the total count as well.
- $totalComments = $this->commentRepo->getCommentCount($pageId);
- return response()->json(array('success' => true, 'comments'=> $comments, 'total' => $totalComments));
- }
- return response()->json(array('success' => true, 'comments'=> $comments));
+ /**
+ * Delete a comment from the system.
+ */
+ public function destroy(int $id)
+ {
+ $comment = $this->commentRepo->getById($id);
+ $this->checkOwnablePermission('comment-delete', $comment);
+
+ $this->commentRepo->delete($comment);
+ return response()->json(['message' => trans('entities.comment_deleted')]);