Game-Jaming/Backend/Controllers/keyWordsRemaining.php

39 lines
1.2 KiB
PHP
Raw Normal View History

2021-03-05 09:52:42 +00:00
<?php
2021-03-08 12:01:01 +00:00
require "../../bootstrap.php";
2021-03-05 09:52:42 +00:00
use Backend\Models\Group;
use Backend\Models\KeyWord;
session_start();
2021-03-05 09:52:42 +00:00
if (session_status() === PHP_SESSION_ACTIVE) {
if(isset($_POST['submitKeyWord'])){
//Find the group id
$group = Group::find($_SESSION['groupId']);
//if statement to find out if the group have use all their keyWords
if(KeyWord::where('group_id', $group->id)->count()<$group->groupAmount){
//Make a new keyword[Only to be used if you need to make a new of something]
$keyword = new KeyWord();
//Take the keyWord the user typed and set it equal to the keyword valuable
2021-03-08 12:09:50 +00:00
$keyword->key_word = $_POST['key_word'];
2021-03-05 09:52:42 +00:00
//Make foreign key from the groups table to the keyWords table
$keyword->group()->associate($group);
2021-03-05 09:52:42 +00:00
//Try to save it
if(!$keyword->save()){
header("location: ../Frontend/index.php?created=failed");
}else{
header("location: ../Frontend/index.php?created=success");
}
}
2021-03-05 09:52:42 +00:00
//TODO make toast feedback
}
}else{
header("location: ../Frontend/index.php?login=notLoggein");
}