/** * Report comment * * @param $comment * @return mixed */ public function report($comment) { $comment = $this->comment->findById($comment, $this->currentUser); if (!$comment) { throw new NotFoundHttpException(); } $this->report->createCommentReport($this->currentUser, $comment); return []; }
/** * Delete comment by id * * @param $commentId */ public function delete($commentId) { $comment = $this->comment->findById($commentId); $sub = !$comment->parent_id ? $comment->comments + 1 : 1; $this->post->update($comment->post, ['comments' => $comment->post->comments - $sub]); if ($comment->parent) { $this->comment->update($comment->parent, ['comments' => $comment->parent->comments - 1]); } $this->comment->delete($comment); }
/** * Create a new comment * * @param User $user * @param Post $post * @param array $data * @return \Smile\Models\Comment */ public function comment(User $user, Post $post, array $data) { $data['user_id'] = $user->id; $data['post_id'] = $post->id; $this->post->update($post, ['comments' => $post->comments + 1]); // Update the parent of the comment with the right number of comments if (isset($data['parent_id'])) { $parent = $this->comment->findById($data['parent_id']); $this->comment->update($parent, ['comments' => $parent->comments + 1]); } $comment = $this->comment->create($data); if ($comment) { event(new CommentWasCreated($user, $post, $comment)); } return $comment; }