Added files

This commit is contained in:
neerholt
2021-03-10 14:16:08 +01:00
parent 29e9bf10f3
commit 246cfad08a
5 changed files with 76 additions and 1 deletions
@@ -0,0 +1,38 @@
<?php
require "../../bootstrap.php";
use Backend\Models\Group;
use Backend\Models\KeyWord;
session_start();
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
$keyword->key_word = $_POST['key_word'];
//Make foreign key from the groups table to the keyWords table
$keyword->group()->associate($group);
//Try to save it
if(!$keyword->save()){
header("location: ../Frontend/index.php?created=failed");
}else{
header("location: ../Frontend/index.php?created=success");
}
}
//TODO make toast feedback
}
}else{
header("location: ../Frontend/index.php?login=notLoggein");
}