CreateQuestionChoicesTable::up()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 16
rs 9.8666
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7
class CreateQuestionChoicesTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        if (Schema::hasTable('question_choices')) return;
17
        
18
        Schema::create('question_choices', function (Blueprint $table) {
19
            $table->increments('id');
20
            $table->integer('question_id')->unsigned()->index();
21
            $table->enum('is_right_choice', [0, 1])->nullable();
22
            $table->text('choice');
23
            $table->timestamps();
24
25
            $table->foreign('question_id')
26
                  ->references('id')
27
                  ->on('quiz_questions')
28
                  ->onDelete('cascade')
29
                  ->onUpdate('cascade');
30
        });
31
    }
32
33
    /**
34
     * Reverse the migrations.
35
     *
36
     * @return void
37
     */
38
    public function down()
39
    {
40
        Schema::dropIfExists('question_choices');
41
    }
42
}
43