build: initialize RetroHub with Laravel, Inertia, Vue, and Horizon
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Features\Consoles\Data\ConsoleData;
|
||||
use App\Features\Consoles\Models\Console;
|
||||
use App\Features\Games\Data\DashboardStatsData;
|
||||
use App\Features\Games\Data\GameData;
|
||||
use App\Features\Games\Repositories\GameRepository;
|
||||
use App\Features\Games\Repositories\RomFileRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private GameRepository $gameRepository,
|
||||
private RomFileRepository $romFileRepository
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
$stats = new DashboardStatsData(
|
||||
totalGames: $this->gameRepository->count(),
|
||||
totalConsoles: Console::count(),
|
||||
totalRoms: $this->romFileRepository->count(),
|
||||
userSaves: $user->saveFiles()->count(),
|
||||
);
|
||||
|
||||
$recentGames = $this->gameRepository->getRecent(10)
|
||||
->map(fn ($game) => GameData::fromModel($game));
|
||||
|
||||
$consoles = Console::withCount('games')->get()
|
||||
->map(fn ($console) => ConsoleData::fromModel($console));
|
||||
|
||||
return Inertia::render('Dashboard/Index', [
|
||||
'stats' => $stats,
|
||||
'recentGames' => $recentGames,
|
||||
'consoles' => $consoles,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user