Game-Jaming/Backend/Controllers/keyWord/GetKeyWinner.php

24 lines
945 B
PHP
Raw Normal View History

2021-03-10 13:16:08 +00:00
<?php
2021-03-11 12:20:10 +00:00
require_once "../../../bootstrap.php";
require_once "../Admin/Admin.php";
use Backend\Models\Group;
use \Backend\Models\KeyWord;
use \Backend\Models\GameJam;
use \Illuminate\Support\Collection;
if (!isAdmin()){
2021-03-19 08:18:19 +00:00
if(isset($_GET['genKeyWord'])){
$gameJamId = $_GET['gameJamId'];
2021-03-11 12:20:10 +00:00
$game_jam = GameJam::find($gameJamId);
$all_group_in_game_jam_id = Group::where("game_jam_id", $game_jam->id)->pluck("id")->toArray();
$find_all_keywords = KeyWord::whereIn("group_id", $all_group_in_game_jam_id)->inRandomOrder()->get();
$game_jam->key_word = $find_all_keywords->first()->key_word;
$game_jam->save();
2021-03-19 08:18:19 +00:00
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept");
2021-03-11 12:20:10 +00:00
header('Content-Type: application/json;charset=UTF-8');
echo $find_all_keywords->pluck("key_word")->toJson(JSON_PRETTY_PRINT);
}
}