PixelPlacerBot/app/Http/Controllers/CurrentStateController.php

22 lines
570 B
PHP
Raw Permalink Normal View History

2024-07-28 18:06:05 -04:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\CurrentState;
use App\Models\GameSession;
class CurrentStateController extends Controller
{
public function index()
{
$currentGame = GameSession::whereNull('ended_at')->latest()->first();
if (!$currentGame) {
return response()->json(['error' => 'No active game session'], 404);
}
$currentState = CurrentState::where('game_session_id', $currentGame->id)->with('color')->get();
return response()->json($currentState);
}
}