-
- public function getPageComments($pageId) {
- 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->getPageComments($pageId);
- return response()->json(['success' => true, 'comments'=> $comments['comments'],
- 'total' => $comments['total'], 'permissions' => [
- 'comment_create' => $this->currentUser->can('comment-create-all'),
- 'comment_update_own' => $this->currentUser->can('comment-update-own'),
- 'comment_update_all' => $this->currentUser->can('comment-update-all'),
- 'comment_delete_all' => $this->currentUser->can('comment-delete-all'),
- 'comment_delete_own' => $this->currentUser->can('comment-delete-own'),
- ], 'user_id' => $this->currentUser->id]);
+ /**
+ * Delete a comment from the system.
+ * @param integer $id
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function destroy($id)
+ {
+ $comment = $this->commentRepo->getById($id);
+ $this->checkOwnablePermission('comment-delete', $comment);
+ $this->commentRepo->delete($comment);
+ return response()->json(['message' => trans('entities.comment_deleted')]);