wangcb / permission
permission for thinkphp6
Requires
- php: >=7.1.0
- topthink/framework: ^6.0.0
- topthink/think-orm: ^2.0
README
/* Navicat MySQL Data Transfer
Source Server : 192.168.1.186 Source Server Version : 50542 Source Host : 192.168.1.186:3306 Source Database : ruanwen
Target Server Type : MYSQL Target Server Version : 50542 File Encoding : 65001
Date: 2020-06-08 15:53:46 */
SET FOREIGN_KEY_CHECKS=0;
-- Table structure for model_has_permissions
DROP TABLE IF EXISTS model_has_permissions
;
CREATE TABLE model_has_permissions
(
permission_id
bigint(20) unsigned NOT NULL,
model_type
varchar(190) COLLATE utf8mb4_unicode_ci NOT NULL,
model_id
bigint(20) unsigned NOT NULL,
PRIMARY KEY (permission_id
,model_id
,model_type
),
KEY model_has_permissions_model_id_model_type_index
(model_id
,model_type
) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Table structure for model_has_roles
DROP TABLE IF EXISTS model_has_roles
;
CREATE TABLE model_has_roles
(
role_id
bigint(20) unsigned NOT NULL,
model_type
varchar(190) COLLATE utf8mb4_unicode_ci NOT NULL,
model_id
bigint(20) unsigned NOT NULL,
PRIMARY KEY (role_id
,model_id
,model_type
),
KEY model_has_roles_model_id_model_type_index
(model_id
,model_type
) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Table structure for permissions
DROP TABLE IF EXISTS permissions
;
CREATE TABLE permissions
(
id
bigint(20) unsigned NOT NULL AUTO_INCREMENT,
parent_id
int(11) NOT NULL DEFAULT '0',
name
varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '接口地址',
display_name
varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '名称',
url
varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '页面路由',
guard_name
varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
sort
smallint(6) NOT NULL DEFAULT '0' COMMENT '排序,数字越大越在前面',
icon
varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
created_time
timestamp NULL DEFAULT NULL,
updated_time
timestamp NULL DEFAULT NULL,
type
tinyint(1) NOT NULL DEFAULT '0' COMMENT '0菜单,1按钮',
PRIMARY KEY (id
)
) ENGINE=MyISAM AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Table structure for role_has_permissions
DROP TABLE IF EXISTS role_has_permissions
;
CREATE TABLE role_has_permissions
(
permission_id
bigint(20) unsigned NOT NULL,
role_id
bigint(20) unsigned NOT NULL,
PRIMARY KEY (permission_id
,role_id
),
KEY role_has_permissions_role_id_foreign
(role_id
) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Table structure for roles
DROP TABLE IF EXISTS roles
;
CREATE TABLE roles
(
id
bigint(20) unsigned NOT NULL AUTO_INCREMENT,
name
varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
description
varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
guard_name
varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'web',
create_time
timestamp NULL DEFAULT NULL,
update_time
timestamp NULL DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=MyISAM AUTO_INCREMENT=24 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
#安装方法
composer require wangcb/permission
#User模型类加
class User extend Model{ use HasRole; }
$res = $user->getAllPermissions(); //获取所有权限
$user->can('/auth/add');//判断是否有权限
$res = $user->getMenu(); //获取权限菜单树
$user->getRoles();//获取用户角色
$user->clearRole();//删除用户所有角色
$user->roles([1,2,3]);//给用户分配角色