/** * Display a listing of the resource. * * @return Response */ public function index() { // Display the forum index // Get the list of forums the user can access $accessCollection = Auth::user()->forumAccess; // Get the list of forums the user has access to $forums = Forum::whereIn('id', $accessCollection)->orderBy('display_order', 'ASC')->get(); $latestPosts = Post::topic()->with('forum')->whereIn('forum_id', $accessCollection)->orderBy('created_at', 'DESC')->limit(4)->get(); // Get the online users $fiveMinutesAgo = Carbon::now()->subMinutes(5); $usersOnline = User::where('active_at', '>=', $fiveMinutesAgo)->orderBy('active_at', 'DESC')->get(); return view('forums.forum')->withForums($forums)->withLatestPosts($latestPosts)->withOnlineUsers($usersOnline); }