public function viewPost($forum_id, $post_id) { try { $post = ForumPost::with('replies')->where('id', $post_id)->firstOrFail(); $data = $this->buildData(); $data['post'] = $post; return view('laravel-forum::forum.thread', $data); } catch (Exception $e) { return view('laravel-forum::errors.404'); } }
/** * Get a users post count (posts created and replies). * @param int $user_id User Id. * @return int */ public function getPostCount($user_id) { /* Get count from forum posts */ try { $posts = ForumPost::where('author_id', $user_id)->get(); $posts = count($posts); } catch (Exception $e) { $posts = 0; } /* Get count from forum replies */ try { $replies = ForumReply::where('author_id', $user_id)->get(); $replies = count($replies); } catch (Exception $e) { $replies = 0; } /* Return total */ return $posts + $replies; }
private function postExists($post_id) { try { $post = ForumPost::where('id', $post_id)->firstOrFail(); return $post; } catch (\Exception $e) { return false; } }