CreateRoleUserTable::up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 21
rs 9.7998
c 2
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 CreateRoleUserTable extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        Schema::create('role_user', function (Blueprint $table) {
17
            $pkMethod = config('rakshak.users.pk_type', 'uuid');
18
            // dd('pkMethod: ' . $pkMethod);
19
20
            $table->{$pkMethod}('user_id');
21
            $table->uuid('role_id');
22
            $table->timestamps();
23
24
            $table->foreign('user_id')
25
                ->references('id')
26
                ->on('users')
27
                ->onDelete('cascade');
28
29
            $table->foreign('role_id')
30
                ->references('id')
31
                ->on('roles')
32
                ->onDelete('cascade');
33
34
            $table->primary(['user_id', 'role_id']);
35
        });
36
    }
37
38
    /**
39
     * Reverse the migrations.
40
     *
41
     * @return void
42
     */
43
    public function down()
44
    {
45
        Schema::dropIfExists('role_user');
46
    }
47
}
48