cardRepository = $cardRepository; } public function index() { try { $cards = app('App\Repositories\CardRepositoryInterface')->all(); return Inertia::render('cards/shuffle', [ 'cards' => $cards, ]); } catch (\Exception $e) { // Log the error for debugging Log::error('Error fetching cards: '.$e->getMessage(), [ 'trace' => $e->getTraceAsString() ]); // Optionally, you can return an Inertia error page or empty array return Inertia::render('Cards/Index', [ 'cards' => [], 'error' => 'Impossible de récupérer les cartes pour le moment.' ]); } } public function drawCard(Request $request) { // Validate the request if needed $request->validate([ 'count' => 'sometimes|integer' ]); $cardDraw = $this->cardRepository->draw($request->count); // Return the response (Inertia will automatically handle this) return response()->json([ 'success' => true, 'card' => $cardDraw, 'message' => 'Card drawn successfully' ]); } public function cartResult() { return Inertia::render('cards/resultat', [ ]); } public function freeCartResult($id) { $card = $this->cardRepository->find($id); return response()->json([ 'success' => true, 'cards' => $card, ]); } }