作者:梦春情初开 | 来源:互联网 | 2024-09-29 11:44
rbac4表常规设计设计模型:1、管理员表(users)Schema::create('users',function(Blueprint$table){$tabl
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‘);
});