Completed
Push — master ( 46cb86...98cd67 )
by Ben
11s
created

CreateProductCategoriesTable::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 9.6666
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7
class CreateProductCategoriesTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        Schema::create('product_categories', function (Blueprint $table) {
17
            $table->increments('id');
18
            $table->string('name');
19
            $table->string('slug');
20
            $table->integer('parent_id')->nullable();
21
            $table->timestamps();
22
        });
23
24
        Schema::create('product_categories_xref', function (Blueprint $table){
25
            $table->string('product_type');
26
            $table->integer('product_id')->unsigned();
27
            $table->integer('category_id')->unsigned();
28
29
            $table->foreign('product_id')->references('id')->on('products');
30
            $table->foreign('category_id')->references('id')->on('product_categories');
31
        });
32
    }
33
34
    /**
35
     * Reverse the migrations.
36
     *
37
     * @return void
38
     */
39
    public function down()
40
    {
41
        Schema::table('product_categories_xref', function (Blueprint $table) {
42
            $table->dropForeign(['product_id']);
43
            $table->dropForeign(['category_id']);
44
        });
45
46
        Schema::dropIfExists('product_categories');
47
        Schema::dropIfExists('product_categories_xref');
48
    }
49
}
50