Added routes, endpoints to get all matches, get a specific match, create a match, join a match, and update the match

This commit is contained in:
2025-12-18 20:29:10 +00:00
parent 5270e3c093
commit b485e19c9d
5 changed files with 235 additions and 8 deletions
+12 -8
View File
@@ -6,6 +6,7 @@ use App\Models\Game;
use Illuminate\Http\Request;
use App\Http\Requests\StoreGameRequest;
use Illuminate\Support\Facades\Auth;
use App\Models\MatchGame;
class GameController extends Controller
{
@@ -34,15 +35,18 @@ class GameController extends Controller
$user = Auth::user();
$activeGame = Game::where(function ($query) use ($user) {
$query->where('player1_user_id', $user->id)
->orWhere('player2_user_id', $user->id);
})
->whereIn('status', ['Pending', 'Playing'])
->exists();
$activeMatch = MatchGame::where(function ($q) use ($user) {
$q->where('player1_user_id', $user->id)
->orWhere('player2_user_id', $user->id);
})->whereIn('status', ['Pending', 'Playing'])->exists();
if ($activeGame) {
return response()->json(['message' => 'You already have an active game.'], 400);
$activeGame = Game::where(function ($q) use ($user) {
$q->where('player1_user_id', $user->id)
->orWhere('player2_user_id', $user->id);
})->whereIn('status', ['Pending', 'Playing'])->exists();
if ($activeMatch || $activeGame) {
return response()->json(['message' => 'You already have an active game or match.'], 400);
}
$game = Game::create([