new db migration
This commit is contained in:
parent
01f6e16283
commit
d2182f5020
|
@ -10,6 +10,7 @@ Capsule::schema()->create("game_data", function (Blueprint $table){
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string("gameLink");
|
$table->string("gameLink");
|
||||||
$table->boolean("isWebBased");
|
$table->boolean("isWebBased");
|
||||||
|
$table->string("img");
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,6 @@ Capsule::schema()->create("groups", function (Blueprint $table){
|
||||||
$table->string("groupName");
|
$table->string("groupName");
|
||||||
$table->integer("groupAmount");
|
$table->integer("groupAmount");
|
||||||
$table->foreignId("game_jam_id")->constrained("game_jams");
|
$table->foreignId("game_jam_id")->constrained("game_jams");
|
||||||
$table->integer("votes")->nullable();
|
|
||||||
$table->foreignId("password_id")->constrained("passwords");
|
|
||||||
$table->foreignId("game_data_id")->nullable()->constrained("game_data");
|
$table->foreignId("game_data_id")->nullable()->constrained("game_data");
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Schema;
|
||||||
//Create password table with the rows as id, password, rememberToken and timestamps
|
//Create password table with the rows as id, password, rememberToken and timestamps
|
||||||
Capsule::schema()->create("passwords", function (Blueprint $table){
|
Capsule::schema()->create("passwords", function (Blueprint $table){
|
||||||
$table->id();
|
$table->id();
|
||||||
|
$table->foreignId("group_id")->constrained("groups");
|
||||||
$table->string('password');
|
$table->string('password');
|
||||||
$table->rememberToken();
|
$table->rememberToken();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
require_once "../../bootstrap.php";
|
||||||
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
|
||||||
|
Capsule::schema()->create("votes", function (Blueprint $table){
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId("group_id")->constrained("groups");
|
||||||
|
$table->tinyInteger("points");
|
||||||
|
$table->text("comment")->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
require "GameJam.php"; //GameJam has no foreign key
|
require "GameJam.php"; //GameJam has no foreign key
|
||||||
require "GameData.php"; //GameData has no foreign key
|
require "GameData.php"; //GameData has no foreign key
|
||||||
require "Password.php"; //Password has no foreign key
|
|
||||||
require "Group.php"; //Group has foreign keys to the GameJam, GameData and Password tables hence we create it as one of the last tables in the database
|
require "Group.php"; //Group has foreign keys to the GameJam, GameData and Password tables hence we create it as one of the last tables in the database
|
||||||
|
require "Password.php"; //Password has no foreign key
|
||||||
require "KeyWord.php"; //Group has foreign keys to the Group
|
require "KeyWord.php"; //Group has foreign keys to the Group
|
||||||
|
require "Vote.php";
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
<?php
|
|
||||||
//require bootstrap aka our database connection
|
|
||||||
require_once "../../bootstrap.php";
|
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
//Create has_voted table with the rows as id and timestamp
|
|
||||||
Capsule::schema()->create("has_voted", function (Blueprint $table){
|
|
||||||
$table->id();
|
|
||||||
$table->timestamps();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Syntex to create table in database
|
|
||||||
|
|
||||||
$table->string("texts");
|
|
||||||
|
|
||||||
$table => valuable;
|
|
||||||
string => datatype;
|
|
||||||
("texts") => name for the row in the database
|
|
||||||
*/
|
|
|
@ -17,6 +17,6 @@ class Group extends Eloquent
|
||||||
return $this->belongsTo(GameData::class);
|
return $this->belongsTo(GameData::class);
|
||||||
}
|
}
|
||||||
public function password(){
|
public function password(){
|
||||||
return $this->belongsTo(Password::class);
|
return $this->hasOne(Password::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Password extends Eloquent{
|
||||||
|
|
||||||
|
|
||||||
public function group(){
|
public function group(){
|
||||||
return $this->hasOne(Group::class);
|
return $this->belongsTo(Group::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Backend\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
|
||||||
class hasVoted extends Eloquent{
|
|
||||||
protected $fillable =[
|
|
||||||
'ipaddress'
|
|
||||||
];
|
|
||||||
public function gameData(){
|
|
||||||
return $this->belongsTo(GameData::class);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -14,29 +14,28 @@ $errors = array();
|
||||||
if(isset($_POST['reg_group'])){
|
if(isset($_POST['reg_group'])){
|
||||||
|
|
||||||
|
|
||||||
$password = New Password();
|
|
||||||
|
|
||||||
$password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT);
|
|
||||||
|
|
||||||
if(!$password->save()){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$group = new Group();
|
$group = new Group();
|
||||||
|
|
||||||
$group->password()->associate($password);
|
|
||||||
|
|
||||||
$group->gameJam()->associate(GameJam::find($_POST['gameJamId']));
|
$group->gameJam()->associate(GameJam::find($_POST['gameJamId']));
|
||||||
|
|
||||||
$group->groupName = $groupName = $_POST['groupName'];
|
$group->groupName = $groupName = $_POST['groupName'];
|
||||||
|
|
||||||
$group->groupAmount = $_POST['groupAmount'];
|
$group->groupAmount = $_POST['groupAmount'];
|
||||||
|
|
||||||
$group->votes = 0;
|
|
||||||
|
|
||||||
if(!$group->save()){
|
if(!$group->save()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$password = New Password();
|
||||||
|
|
||||||
|
$password->group()->associate($group);
|
||||||
|
|
||||||
|
$password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT);
|
||||||
|
|
||||||
|
if(!$password->save()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$_SESSION['groupName'] = $groupName;
|
$_SESSION['groupName'] = $groupName;
|
||||||
$_SESSION['success'] = "You are now logged in";
|
$_SESSION['success'] = "You are now logged in";
|
||||||
|
|
Loading…
Reference in New Issue