Fixed keyword upload error and you are now only able to upload the same amount of keywords as there group members

This commit is contained in:
neerholt
2021-03-08 10:03:06 +01:00
parent 93b9411c99
commit 04372b3539
2 changed files with 65 additions and 52 deletions
+24 -6
View File
@@ -4,15 +4,33 @@ use Backend\Models\Group;
use Backend\Models\KeyWord;
if(isset($_POST['submitKeyWord'])){
$keyword = new KeyWord();
//Find the group id
$group = Group::find($_POST['group_id']);
$keyword->keyWord = $_POST['key_word'];
//if statement to find out if the group have use all their keyWords
if(KeyWord::where('group_id', $group->id)->count()<$group->groupAmount){
$keyword->group()->associate(Group::find($_POST['group_id']));
//Make a new keyword[Only to be used if you need to make a new of something]
$keyword = new KeyWord();
if(!$keyword->save()){
return;
//Take the keyWord the user typed and set it equal to the keyword valuable
$keyword->keyWord = $_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
}