- if (empty($commentId)) {
- // create a new comment.
- $this->checkPermission('comment-create-all');
- $comment = $this->commentRepo->create($page, $request->only(['text', 'html', 'parent_id']));
- $respMsg = trans('entities.comment_created');
- } else {
- // update existing comment
- // get comment by ID and check if this user has permission to update.
- $comment = $this->comment->findOrFail($commentId);
- $this->checkOwnablePermission('comment-update', $comment);
- $this->commentRepo->update($comment, $request->all());
- $respMsg = trans('entities.comment_updated');
- }
-
- return response()->json([
- 'status' => 'success',
- 'message' => $respMsg
- ]);
-
- }