gameRepository->getBySlug($slug); abort_unless($game, 404); return Inertia::render('Games/Show', [ 'game' => GameData::fromModel($game), ]); } public function edit(string $slug): Response { $game = $this->gameRepository->getBySlug($slug); abort_unless($game, 404); return Inertia::render('Games/Edit', [ 'game' => GameData::fromModel($game), 'consoles' => Console::orderBy('name')->get(), ]); } public function update(Request $request, string $slug): RedirectResponse { $game = $this->gameRepository->getBySlug($slug); abort_unless($game, 404); $validated = $request->validate([ 'title' => 'required|string|max:255', 'description' => 'nullable|string', 'release_year' => 'nullable|integer|min:1970|max:2030', 'developer' => 'nullable|string|max:255', 'publisher' => 'nullable|string|max:255', 'genre' => 'nullable|string|max:255', 'rating' => 'nullable|numeric|min:0|max:10', ]); $game->update($validated); return redirect()->route('games.show', $game) ->with('success', 'Game updated successfully.'); } public function destroy(string $slug): RedirectResponse { $game = $this->gameRepository->getBySlug($slug); abort_unless($game, 404); $romFiles = $this->romFileRepository->getByGame($game->id); foreach ($romFiles as $romFile) { Storage::disk('local')->delete($romFile->file_path); $romFile->delete(); } if ($game->cover_path) { Storage::disk('local')->delete($game->cover_path); } $console = $game->console; $game->delete(); return redirect()->route('consoles.show', $console->slug) ->with('success', 'Game deleted successfully.'); } public function download(string $slug, int $romFileId): StreamedResponse { $game = $this->gameRepository->getBySlug($slug); abort_unless($game, 404); $romFile = $this->romFileRepository->getByGame($game->id)->where('id', $romFileId)->first(); abort_unless($romFile, 404); return Storage::disk('local')->download( $romFile->file_path, $romFile->file_name ); } }