parent_id != 0) { return redirect()->route('forums.show', ['id' => $forum->id]); } // Check if the user has permission to view the forum $category = Forum::findOrFail($forum->id); if ($category->getPermission()->show_forum != true) { return redirect()->route('forums.index') ->withErrors('You Do Not Have Access To This Category!'); } // Fetch topics->posts in descending order $topics = $forum->sub_topics()->latest('pinned')->latest('last_reply_at')->latest()->paginate(25); return view('forum.category', [ 'forum' => $forum, 'topics' => $topics, 'category' => $category, 'num_posts' => $num_posts, 'num_forums' => $num_forums, 'num_topics' => $num_topics, ]); } }