validate([ 'session_name' => 'required|string|max:255', 'palette_id' => 'required|exists:palettes,id', 'image_path' => 'required|string' ]); $gameSession = GameSession::create([ 'session_name' => $request->session_name, 'palette_id' => $request->palette_id, 'image_path' => $request->image_path, ]); // Logic to initialize the winning state based on the provided image // ... return response()->json($gameSession); } public function end(Request $request, $id) { $gameSession = GameSession::findOrFail($id); $gameSession->update(['ended_at' => now()]); return response()->json($gameSession); } public function current() { $currentGame = GameSession::whereNull('ended_at')->latest()->first(); return response()->json($currentGame); } public function getCurrentGameSession() { $gameSession = GameSession::whereNull('ended_at')->latest()->first(); if (!$gameSession) { $gameSession = GameSession::create(['session_name' => 'Session ' . now(), 'palette_id' => 1, 'image_path' => '']); } return $gameSession; } }