Game-Jaming/Backend/Controllers/Group/GetGroup.php

18 lines
645 B
PHP

<?php
require_once "../../../bootstrap.php";
use Backend\Models\Group;
if (isset($_GET["groupId"])) {
$groups = Group::find($_GET["groupId"]);
} elseif (isset($_GET["gameJameId"])) {
$registrationIds = Registration::where("game_jam_id", $_GET["gameJameId"])->pluck("game_data_id")->toArray();
$groups = Group::whereIn("id", $registrationIds)->get();
} else {
$groups = Group::all();
}
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept");
header('Content-Type: application/json;charset=UTF-8');
echo json_encode(array('data' => $groups->jsonSerialize()));