CreatePermissionRoleTable::up()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 0
dl 0
loc 17
rs 9.7998
c 0
b 0
f 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 CreatePermissionRoleTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        $connection = config('roles.connection');
17
        $table = config('roles.permissionsRoleTable');
18
        $permissionsTable = config('roles.permissionsTable');
19
        $rolesTable = config('roles.rolesTable');
20
        $tableCheck = Schema::connection($connection)->hasTable($table);
21
22
        if (!$tableCheck) {
23
            Schema::connection($connection)->create($table, function (Blueprint $table) use ($permissionsTable, $rolesTable) {
24
                $table->increments('id')->unsigned();
25
                $table->integer('permission_id')->unsigned()->index();
26
                $table->foreign('permission_id')->references('id')->on($permissionsTable)->onDelete('cascade');
27
                $table->integer('role_id')->unsigned()->index();
28
                $table->foreign('role_id')->references('id')->on($rolesTable)->onDelete('cascade');
29
                $table->timestamps();
30
                $table->softDeletes();
31
            });
32
        }
33
    }
34
35
    /**
36
     * Reverse the migrations.
37
     *
38
     * @return void
39
     */
40
    public function down()
41
    {
42
        $connection = config('roles.connection');
43
        $table = config('roles.permissionsRoleTable');
44
        Schema::connection($connection)->dropIfExists($table);
45
    }
46
}
47