AddColumnsToUsersTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 6 1
A down() 0 9 2
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\DB;
6
use Illuminate\Support\Facades\Schema;
7
8
class AddColumnsToUsersTable extends Migration
9
{
10
    /**
11
     * Run the migrations.
12
     *
13
     * @return void
14
     */
15
    public function up()
16
    {
17
        Schema::table('users', function (Blueprint $table) {
18
            $table->foreignId('role_id')->after('email')->nullable()->constrained()->onDelete('set null');
19
        });
20
    }
21
22
    /**
23
     * Reverse the migrations.
24
     *
25
     * @return void
26
     */
27
    public function down()
28
    {
29
        Schema::table('users', function (Blueprint $table) {
30
            if (DB::getDefaultConnection() !== 'sqlite') {
31
                $table->dropForeign(['role_id']);
32
            }
33
            $table->dropColumn(['role_id']);
34
        });
35
    }
36
}
37