权限系统 这样的数据库是否可行?

  1. 如下数据库是否可行? 有什么问题?
  2. 中间件是否可以获取到具体的路由信息 , 设想是根据路由信息 从数据库中获取权限 然后验证权限 如果不能取得具体的路由信息 这一步就走不通
    /**

    • 权限表
      */
      Schema::create('permission', function (Blueprint $table) {
      $table->increments('id');
      $table->string('name',50);
      $table->timestamps();
      });

      /**

    • 功能模块表 每一个功能对应一个页面上的菜单 对应一个路由路径
      */
      Schema::create('module', function (Blueprint $table) {
      $table->increments('id');
      $table->integer('fid');
      $table->string('name',50);
      $table->integer('routeid');
      $table->timestamps();
      });

      /**

    • 路由表 定义每个路由所需要的权限 通过中间件验证权限
      */
      Schema::create('route', function (Blueprint $table) {
      $table->increments('id');
      $table->string('route');
      $table->string('method');
      $table->string('permissions');
      $table->string('description');
      $table->timestamps();
      });

      /**

    • 角色表
      */
      Schema::create('roles', function (Blueprint $table) {
      $table->increments('id');
      $table->string('name');
      $table->string('description');
      $table->timestamps();
      });

      /**

    • 用户表
      */
      Schema::create('users', function (Blueprint $table) {
      $table->increments('id');
      $table->string('mobile', 13)->unique();
      $table->string('password');
      $table->string('name');
      $table->integer('departmentid');
      $table->integer('sex');
      $table->string('phone');
      $table->rememberToken();
      $table->timestamps();
      });

      /**

    • 用户 - 角色表
      */
      Schema::create('userRoles', function (Blueprint $table) {
      $table->increments('id');
      $table->integer('userid');
      $table->integer('roleid');
      $table->timestamps();
      });

      /**

    • 角色 - 权限表
      */
      Schema::create('rolePermissions', function (Blueprint $table) {
      $table->increments('id');
      $table->integer('roleid');
      $table->integer('permissionid');
      $table->timestamps();
      });
phpwebstudy, mac php 环境终极解决方案 www.macphpstudy.com
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1
  1. 首先回答你第一个问题,你设计的数据库是可行的,ACL 权限系统一般都是 User-Role-Permission。
    但是路由拦截这个表不应该放在数据库中,应该放在中间件中,因为在数据库中你不方便实现路由匹配
  2. 第二个问题,中间件中是可以获得 request uri 的。这个是没有问题的。

关于简易的权限系统,我前两天刚写了一个,有一些思考在这里:
https://segmentfault.com/a/119000000844711...

8年前 评论