CreateGuardianTables   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 64
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 0 44 3
A down() 0 6 1
1
<?php
2
3
use Illuminate\Database\Schema\Blueprint;
4
use Illuminate\Database\Migrations\Migration;
5
6
use EmilMoe\Guardian\Support\Guardian;
7
8
class CreateGuardianTables 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...
9
{
10
    /**
11
     * Run the migrations.
12
     *
13
     * @return void
14
     */
15
    public function up()
16
    {
17
        Schema::create(config('guardian.table.permission'), function (Blueprint $table) {
18
            $table->increments('id');
19
            $table->string('name')->unique();
20
            $table->string('table');
21
            $table->string('foreign_id_column');
22
            $table->string('user_id_column');
23
            $table->timestamps();
24
        });
25
26
        Schema::create(config('guardian.table.role'), function (Blueprint $table) {
27
            $table->increments('id');
28
            $table->string('name');
29
            $table->boolean('locked')->default(false);
30
31
            if (Guardian::hasClients())
32
                $table->integer(Guardian::getClientColumn())->unsigned();
33
34
            $table->timestamps();
35
36
            if (Guardian::hasClients())
37
                $table->foreign(Guardian::getClientColumn())
38
                    ->references(Guardian::getClientKey())
39
                    ->on(Guardian::getClientTable())
40
                    ->onDelete('cascade');
41
        });
42
43
        Schema::create(config('guardian.table.role') .'_'. config('guardian.table.permission'), function (Blueprint $table) {
44
            $table->integer('permission_id')->unsigned();
45
            $table->integer('role_id')->unsigned();
46
            $table->timestamps();
47
            $table->foreign('permission_id')->references('id')->on(config('guardian.table.permission'))->onDelete('cascade');
48
            $table->foreign('role_id')->references('id')->on(config('guardian.table.role'))->onDelete('cascade');
49
        });
50
51
        Schema::create(Guardian::getUserTable() .'_'. config('guardian.table.role'), function (Blueprint $table) {
52
            $table->integer('user_id')->unsigned();
53
            $table->integer('role_id')->unsigned();
54
            $table->timestamps();
55
            $table->foreign('user_id')->references(Guardian::getUserKey())->on(Guardian::getUserTable())->onDelete('cascade');
56
            $table->foreign('role_id')->references('id')->on(config('guardian.table.role'))->onDelete('cascade');
57
        });
58
    }
59
60
    /**
61
     * Reverse the migrations.
62
     *
63
     * @return void
64
     */
65
    public function down()
66
    {
67
        Schema::drop(config('guardian.table.permission') .'_'. config('guardian.table.role'));
68
        Schema::drop(config('guardian.table.role'));
69
        Schema::drop(config('guardian.table.permission'));
70
    }
71
}
72