$user->library()->where('status', 'played')->count(), 'playing' => $user->library()->where('status', 'playing')->count(), 'want_to_play' => $user->library()->where('status', 'want_to_play')->count(), 'total' => $user->library()->count(), ]; $genreStats = \DB::table('genres') ->select('genres.id', 'genres.name', \DB::raw('COUNT(*) as count')) ->join('game_genre', 'genres.id', '=', 'game_genre.genre_id') ->join('user_games', 'game_genre.game_id', '=', 'user_games.game_id') ->where('user_games.user_id', $user->id) ->whereIn('user_games.status', ['played', 'playing']) ->groupBy('genres.id', 'genres.name') ->orderByDesc('count') ->limit(5) ->get(); $allGames = $user->library() ->with('game') ->latest('updated_at') ->limit(12) ->get(); return view('users.show', compact('user', 'stats', 'genreStats', 'allGames')); } public function library(User $user) { $status = request('status'); $query = $user->library()->with('game'); if ($status && in_array($status, UserGame::STATUSES)) { $query->where('status', $status); } $entries = $query->latest('updated_at')->paginate(24)->withQueryString(); return view('users.library', compact('user', 'entries', 'status')); } }