/** * Shows a specific forum. * * @param Request $request * @param string $slug The slug of the forum to show. * * @param int $id The ID of the forum to show. * * @return \Illuminate\View\View */ public function show(Request $request, $slug = '', $id = 0) { // Forum permissions are checked in "find" $forum = $this->forumRepository->find($id); // Load last post information for child forums $forum->load(['children.lastPost', 'children.lastPost.topic', 'children.lastPostAuthor']); if (!$forum) { throw new ForumNotFoundException(); } $this->breadcrumbs->setCurrentRoute('forums.show', $forum); // Build the order by/dir parts $allowed = ['lastpost', 'replies', 'startdate', 'title']; $orderBy = $request->get('orderBy', 'lastpost'); if (!in_array($orderBy, $allowed)) { $orderBy = 'lastpost'; } $orderDir = $request->get('orderDir', 'desc'); if ($orderDir != 'asc' && $orderDir != 'desc') { $orderDir = 'desc'; } // We need to know how to build the url... $urlDirs = ['lastpost' => 'desc', 'replies' => 'desc', 'startdate' => 'desc', 'title' => 'asc']; if ($orderDir == 'desc' && $urlDirs[$orderBy] == 'desc') { $urlDirs[$orderBy] = 'asc'; } elseif ($orderDir == 'asc' && $urlDirs[$orderBy] == 'asc') { $urlDirs[$orderBy] = 'desc'; } $topics = $this->topicRepository->allForForum($forum, $orderBy, $orderDir); $topics->appends(['orderBy' => $orderBy, 'orderDir' => $orderDir]); return view('forum.show', compact('forum', 'topics', 'orderBy', 'orderDir', 'urlDirs')); }