/**
  * 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);
 }
 /**
  * Show posts from category
  *
  * @param Request $request
  * @param null $slug
  * @return \Illuminate\View\View
  */
 public function category(Request $request, $slug = null)
 {
     $category = !$slug ? $this->category->first() : $this->category->findBySlug($slug);
     if (!$category) {
         throw new NotFoundHttpException();
     }
     $posts = $this->post->findByCategory($category, $this->currentUser, 10);
     if ($request->has('ajax')) {
         return $this->jsonPagination($posts, $this->view('ajax.posts', compact('posts')));
     }
     return $this->view('post.list', compact('category', 'posts'));
 }
 /**
  * Get random post
  *
  * @param null|User $user
  * @return mixed
  */
 public function random(User $user = null)
 {
     return $this->post->random($user);
 }