CreateCategorizableTable::down()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
class CreateCategorizableTable 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
    /**
11
     * Run the migrations.
12
     *
13
     * @return void
14
     */
15
    public function up()
16
    {
17
        $connection = config('categorizable.connection');
18
19
        Schema::connection($connection)->create('categories', function (Blueprint $table) {
20
            $table->increments('id');
21
            $table->string('name');
22
23
            $table->nestedSet();
24
            $table->timestamps();
25
        });
26
27
        Schema::connection($connection)->create('categorizable', function (Blueprint $table) {
28
            $table->increments('id');
29
            $table->unsignedInteger('category_id');
30
            $table->nullableMorphs('categorizable');
31
32
            $table->index('categorizable_type', 'categorizable_id');
33
            $table->timestamps();
34
        });
35
    }
36
37
    /**
38
     * Reverse the migrations.
39
     *
40
     * @return void
41
     */
42
    public function down()
43
    {
44
        $connection = config('categorizable.connection');
45
46
        if (Schema::connection($connection)->hasTable('categories')) {
47
            Schema::connection($connection)->drop('categories');
48
        }
49
50
        if (Schema::connection($connection)->hasTable('categorizable')) {
51
            Schema::connection($connection)->drop('categorizable');
52
        }
53
    }
54
}
55