/** * 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); }
/** * Toggle pin * * @param $id * @return bool|mixed */ public function togglePin($id) { $post = $this->post->findById($id); if (!$post) { return false; } $this->post->update($post, ['pinned' => $post->pinned ? false : true]); return $post; }