rbac 4表 常規設計
阿新 • • 發佈:2020-07-20
rbac 4表 常規設計
設計模型:
1、管理員表(users)
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('role_id')->default(0)->comment('角色id');
$table->string('username', 20)->comment('使用者名稱');
$table->string('truename', 50)->default('未知')->comment('真實姓名');
$table->string('password', 255)->comment('密碼');
$table->string('email', 50)->nullable()->comment('郵箱');
$table->string('phone', 15)->default()->comment('手機號碼');
$table->enum('sex',['先生','女士'])->default('先生')->comment('性別');
$table->char('last_ip',15)->default('')->comment('登入ip地址');
$table->timestamps();
// 軟刪除
$table->softDeletes();
});
2、角色表(roles)
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('rolename',20)->comment('角色名稱');
$table->timestamps();
// 軟刪除
$table->softDeletes();
});
3、許可權表(permissions)
Schema::create('permissions', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('PermissionName', 50)->comment('許可權名稱');
$table->string('route_name', 100)->default('')->comment('路由別名,許可權認證標識');
$table->unsignedBigInteger('pid')->default(0)->comment('上級ID');
$table->enum('is_menu', ['0', '1'])->default('0')->comment('是否為選單,0否,1是');
$table->timestamps();
$table->softDeletes();
});
4、角色與許可權的中間表(role_permission)
Schema::create('role_permission',function(Blueprint $table){
// 角色ID
$table->unsignedBigInteger('role_id')->default(0)->comment('角色ID');
// 許可權ID
$table->unsignedBigInteger('permission_id')->default(0)->comment('許可權ID');
});