Passed
Branch master (4ff80c)
by Matt
14:34
created

CreateUserQuestionAnswerTable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 0 30 2
A down() 0 3 1
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7
class CreateUserQuestionAnswerTable extends Migration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        if (Schema::hasTable('user_question_answer')) return;
17
        
18
        Schema::create('user_question_answer', function (Blueprint $table) {
19
            $table->increments('id');
20
            $table->integer('user_id')->unsigned()->index();
21
            $table->integer('question_id')->unsigned()->index();
22
            $table->integer('question_choice_id')->unsigned()->index();
23
            $table->enum('is_right', [0, 1]);
24
            $table->dateTime('answer_time');
25
            $table->timestamps();
26
27
            $table->foreign('user_id')
28
                  ->references('id')
29
                  ->on('users')
30
                  ->onDelete('cascade')
31
                  ->onUpdate('cascade');
32
33
            $table->foreign('question_id')
34
                  ->references('id')
35
                  ->on('quiz_questions')
36
                  ->onDelete('cascade')
37
                  ->onUpdate('cascade');
38
39
            $table->foreign('question_choice_id')
40
                  ->references('id')
41
                  ->on('question_choices')
42
                  ->onDelete('cascade')
43
                  ->onUpdate('cascade');
44
        });
45
    }
46
47
    /**
48
     * Reverse the migrations.
49
     *
50
     * @return void
51
     */
52
    public function down()
53
    {
54
        Schema::dropIfExists('user_question_answer');
55
    }
56
}
57