/** * Delete a post * * @param Post $post The post to delete * * @return mixed */ public function deletePost(Post $post) { if ($post['deleted_at'] == null) { // Update counters $post->topic->decrement('num_posts'); $post->topic->forum->decrement('num_posts'); if ($post->user_id > 0) { $post->author->decrement('num_posts'); } // Delete the post $success = $post->delete(); if ($success) { if ($post->topic->last_post_id == $post->id) { $post->topic->update(['last_post_id' => $post->topic->posts->sortByDesc('id')->first()->id]); } if ($post->topic->forum->last_post_id == $post->id) { $this->forumRepository->updateLastPost($post->topic->forum); } } return $success; } else { $this->likesRepository->removeLikesForContent($post); return $post->forceDelete(); } }
/** * SHow all of the likes a post has received. * * @param int $postId The ID of the post to show the likes for. * * @return \Illuminate\View\View */ public function getPostLikes($postId) { $post = $this->postsRepository->find($postId); if (!$post) { throw new PostNotFoundException(); } $post->load('topic'); $likes = $this->likesRepository->getAllLikesForContentPaginated($post, $this->settings->get('likes.per_page', 10)); return view('post.likes', compact('post', 'likes')); }