CreateRoleUserTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 5 1
A up() 0 16 2
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
class CreateRoleUserTable 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.roleUserTable');
18
        $rolesTable = config('roles.rolesTable');
19
        $tableCheck = Schema::connection($connection)->hasTable($table);
20
21
        if (!$tableCheck) {
22
            Schema::connection($connection)->create($table, function (Blueprint $table) use ($rolesTable) {
23
                $table->increments('id')->unsigned();
24
                $table->integer('role_id')->unsigned()->index();
25
                $table->foreign('role_id')->references('id')->on($rolesTable)->onDelete('cascade');
26
                $table->unsignedBigInteger('user_id')->unsigned()->index();
27
                $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
28
                $table->timestamps();
29
                $table->softDeletes();
30
            });
31
        }
32
    }
33
34
    /**
35
     * Reverse the migrations.
36
     *
37
     * @return void
38
     */
39
    public function down()
40
    {
41
        $connection = config('roles.connection');
42
        $table = config('roles.roleUserTable');
43
        Schema::connection($connection)->dropIfExists($table);
44
    }
45
}
46