Completed
Push — master ( 0eb7b3...2d7f4d )
by wen
03:09
created

RbacSetupTables::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
use Illuminate\Database\Schema\Blueprint;
4
use Illuminate\Database\Migrations\Migration;
5
6
class RbacSetupTables extends Migration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
    /**
9
     * Run the migrations.
10
     *
11
     * @return  void
12
     */
13
    public function up()
14
    {
15
        // Create table for storing roles
16
        Schema::create('roles', function (Blueprint $table) {
17
            $table->engine = "InnoDB COMMENT='角色表'";
18
            $table->increments('id');
19
20
            $table->string('name')
21
                ->unique()
22
                ->comment('名称');
23
24
            $table->string('display_name')
25
                ->comment('显示名');
26
27
            $table->string('description')
28
                ->nullable()
29
                ->comment('备注');
30
31
            $table->timestamps();
32
        });
33
34
        // Create table for associating roles to users (Many-to-Many)
35
        Schema::create('role_user', function (Blueprint $table) {
36
            $table->engine = "InnoDB COMMENT='角色与用户对应表'";
37
            $table->integer(config('admin.user_foreign_key'))
38
                ->unsigned()
39
                ->comment('管理员ID');
40
41
            $table->integer('role_id')
42
                ->unsigned()
43
                ->comment('角色ID');
44
45
            $table->primary([config('admin.user_foreign_key'), 'role_id']);
46
        });
47
48
        // Create table for storing permissions
49
        Schema::create('permissions', function (Blueprint $table) {
50
            $table->engine = "InnoDB COMMENT='权限(即菜单)表'";
51
52
            $table->increments('id')
53
                ->comment('主键');
54
55
            $table->integer('pid')
56
                ->comment('父ID');
57
58
            $table->string('icon', 100)
59
                ->comment('图标class')
60
                ->default('');
61
62
            $table->string('display_name', 200)
63
                ->comment('显示名称');
64
65
            $table->string('name', 100)
66
                ->comment('名称');
67
68
            $table->tinyInteger('is_menu')
69
                ->comment('是否作为菜单')
70
                ->default('1');
71
72
            $table->tinyInteger('sort')
73
                ->unsigned()
74
                ->comment('排序')
75
                ->default('0');
76
77
            $table->string('description')
78
                ->nullable()
79
                ->comment('描述');
80
81
            $table->timestamps();
82
            $table->index('pid');
83
        });
84
85
        // Create table for associating permissions to roles (Many-to-Many)
86
        Schema::create('permission_role', function (Blueprint $table) {
87
            $table->engine = "InnoDB COMMENT='权限与角色对应表'";
88
            $table->integer('permission_id')
89
                ->unsigned()
90
                ->comment('权限ID');
91
92
            $table->integer('role_id')
93
                ->unsigned()
94
                ->comment('角色ID');
95
96
            $table->primary(['permission_id', 'role_id']);
97
        });
98
    }
99
100
    /**
101
     * Reverse the migrations.
102
     *
103
     * @return  void
104
     */
105
    public function down()
106
    {
107
        Schema::drop('permission_role');
108
        Schema::drop('permissions');
109
        Schema::drop('role_user');
110
        Schema::drop('roles');
111
    }
112
}
113