Completed
Push — master ( 93fb68...e8f12d )
by Troy
01:40
created

CreateTenantsTable   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 55
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 0 37 6
A down() 0 4 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 CreateTenantsTable 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
        $table_name = config('multi-tenant.table_name');
17
18
        Schema::create($table_name, function (Blueprint $table) use ($table_name) {
19
            $table->increments('id');
20
            $table->integer('owner_id');
21
            $table->string('name');
22
            $table->string('slug')->unique();
23
24
            foreach(config('multi-tenant.additional_tenant_columns') as $key => $data) {
25
                $type = $data['type'];
26
                $column = $table->$type($key);
27
28
                if ($data['index']) {
29
                    $column->index();
30
                }
31
32
                if ($data['unique']) {
33
                    $column->unique();
34
                }
35
36
                if ($data['unsigned']) {
37
                    $column->unsigned();
38
                }
39
40
                if ($data['nullable']) {
41
                    $column->nullable();
42
                }
43
            }
44
45
            $table->timestamps();
46
47
            $table->index('owner_id', $table_name . '_owner_id_index');
48
            $table->index('slug', $table_name . '_slug_index');
49
        });
50
    }
51
52
    /**
53
     * Reverse the migrations.
54
     *
55
     * @return void
56
     */
57
    public function down()
58
    {
59
        Schema::dropIfExists(config('multi-tenant.table_name'));
60
    }
61
}
62