parent
6196383c0a
commit
bf96efcc64
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PollOption extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['text'];
|
||||
|
||||
public function poll()
|
||||
{
|
||||
return $this->belongsTo('App\Poll');
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PollVote extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
public function poll()
|
||||
{
|
||||
return $this->belongsTo('App\Poll');
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PollVotingCode extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
public $keyType = "string";
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->id = PollVotingCode::createId();
|
||||
}
|
||||
|
||||
private static function createId()
|
||||
{
|
||||
//TODO: Check if id is unique
|
||||
|
||||
$characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
$id = '';
|
||||
for($i = 0; $i < 32; $i++) {
|
||||
$id .= $characters[rand(0, strlen($characters) - 1)];
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function poll()
|
||||
{
|
||||
return $this->belongsTo('App\Poll');
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreatePollOptionsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('poll_options', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('text');
|
||||
$table->char('poll_id', 6);
|
||||
|
||||
$table->foreign('poll_id')->references('id')->on('polls');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$table->dropForeign(['poll_id']);
|
||||
|
||||
Schema::dropIfExists('poll_options');
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreatePollVotingCodesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('poll_voting_codes', function (Blueprint $table) {
|
||||
$table->char('id', 32);
|
||||
$table->boolean('used')->default(false);
|
||||
$table->char('poll_id', 6);
|
||||
|
||||
$table->primary('id');
|
||||
$table->foreign('poll_id')->references('id')->on('polls');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$table->dropForeign(['poll_id']);
|
||||
|
||||
Schema::dropIfExists('poll_voting_codes');
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreatePollVotesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('poll_votes', function (Blueprint $table) {
|
||||
$table->char('poll_id', 6);
|
||||
$table->unsignedInteger('poll_option_id');
|
||||
|
||||
$table->foreign('poll_id')->references('id')->on('polls');
|
||||
$table->foreign('poll_option_id')->references('id')->on('poll_options');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$table->dropForeign(['poll_id', 'poll_option_id']);
|
||||
|
||||
Schema::dropIfExists('poll_votes');
|
||||
}
|
||||
}
|
Loading…
Reference in new issue