CreateRolesTable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 3 1
A up() 0 46 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 CreateRolesTable extends Migration
9
{
10
    /**
11
     * Run the migrations.
12
     *
13
     * @return void
14
     */
15
    public function up()
16
    {
17
        Schema::create('roles', function (Blueprint $table) {
18
            $table->id();
19
            $table->string('name');
20
            $table->text('description')->nullable();
21
            $table->integer('level')->default(0);
22
            $table->timestamps();
23
        });
24
25
        // Migrate with dummy
26
        if (config('adminetic.migrate_with_dummy', false)) {
27
            $roles = [
28
                [
29
                    'name' => 'superadmin',
30
                    'description' => 'This is a super admin user',
31
                    'level' => 5,
32
                ],
33
                [
34
                    'name' => 'admin',
35
                    'description' => 'This is an admin user',
36
                    'level' => 4,
37
                ],
38
                [
39
                    'name' => 'moderator',
40
                    'description' => 'This is an moderator',
41
                    'level' => 3,
42
                ],
43
                [
44
                    'name' => 'editor',
45
                    'description' => 'This is an editor',
46
                    'level' => 2,
47
                ],
48
                [
49
                    'name' => 'user',
50
                    'description' => 'This is an normal user',
51
                    'level' => 1,
52
                ],
53
                [
54
                    'name' => 'unverified',
55
                    'description' => 'This is an unverified user',
56
                    'level' => 0,
57
                ],
58
            ];
59
60
            DB::table('roles')->insert($roles);
61
        }
62
    }
63
64
    /**
65
     * Reverse the migrations.
66
     *
67
     * @return void
68
     */
69
    public function down()
70
    {
71
        Schema::dropIfExists('roles');
72
    }
73
}
74