2026-05-29 09:37:07 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\UserGame;
|
|
|
|
|
|
|
|
|
|
class UserController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function show(User $user)
|
|
|
|
|
{
|
|
|
|
|
$stats = [
|
|
|
|
|
'played' => $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(),
|
|
|
|
|
];
|
|
|
|
|
|
2026-05-30 01:57:35 +03:00
|
|
|
$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)
|
2026-05-29 09:37:07 +03:00
|
|
|
->get();
|
|
|
|
|
|
2026-05-30 01:57:35 +03:00
|
|
|
$allGames = $user->library()
|
|
|
|
|
->with('game')
|
|
|
|
|
->latest('updated_at')
|
|
|
|
|
->limit(12)
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
return view('users.show', compact('user', 'stats', 'genreStats', 'allGames'));
|
2026-05-29 09:37:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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'));
|
|
|
|
|
}
|
|
|
|
|
}
|