diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 7d8ba59..bdc7124 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -16,14 +16,24 @@ class UserController extends Controller 'total' => $user->library()->count(), ]; - $recentlyPlayed = $user->library() - ->with('game') - ->where('status', 'played') - ->latest('updated_at') - ->limit(6) + $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(); - return view('users.show', compact('user', 'stats', 'recentlyPlayed')); + $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) diff --git a/resources/views/games/show.blade.php b/resources/views/games/show.blade.php index 308b356..647452a 100644 --- a/resources/views/games/show.blade.php +++ b/resources/views/games/show.blade.php @@ -119,25 +119,49 @@ @else @auth -
No games tracked yet.
+ {{-- Empty state --}} + @endif