[
  {
    "path": ".gitattributes",
    "content": "/tests export-ignore\nphpunit.xml export-ignore"
  },
  {
    "path": ".gitignore",
    "content": "/.idea\n/vendor\ncomposer.lock\n.phpunit.result.cache"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# Mojito\n\nMojito 是基于 Laravel 开发的 [Mojito Admin](https://github.com/moell-peng/mojito-admin) 的服务端。\n\n3.0 版本开始， 已将原来的项目分离为两个代码库，分别为以Vue3、Element Plus、Vite 开发的前端模板 [mojito -admin](https://github.com/moell-peng/mojito-admin)  和服务端 [mojito](https://github.com/moell-peng/mojito) 。如果是需要使用 vue2 版本，请访问 [2.0](https://github.com/moell-peng/mojito/tree/2.0) 分支。\n\n## Mojito Admin 截图\n\n![mojito.png](http://ww1.sinaimg.cn/large/7a679ca1gy1gtu09c4avej21590kstdb.jpg)\n\n## 特性\n\n* 前后端分离，提供 [Mojito Admin](https://github.com/moell-peng/mojito-admin) 前端模板\n* 基于 laravel-permission 权限管理\n* 基于 sanctum 鉴权 \n* 提供角色，权限，用户，菜单管理等功能的API\n* 多个后台支持统一管理权限，菜单和角色\n* 完善的PHPUnit测试\n\n## 要求\n\n- Laravel  >= 7.0.0\n- PHP >= 7.2.0\n\n## 安装\n\n首先安装laravel,并且确保你配置了正确的数据库连接。\n\n```\ncomposer require moell/mojito\n```\n\n然后运行下面的命令来发布资源:\n\n```\nphp artisan mojito:install\n```\n\n命令执行成功会生成配置文件，数据迁移和构建SPA的文件。\n\n修改 `app/Http/Kernel.php` ：\n\n```\nclass Kernel extends HttpKernel\n{\n    protected $routeMiddleware = [\n        ...\n        'mojito.permission' => \\Moell\\Mojito\\Http\\Middleware\\Authenticate::class,\n    ];\n\n    protected $middlewareGroups = [\n            ...\n            'api' => [\n                ...\n                \\Laravel\\Sanctum\\Http\\Middleware\\EnsureFrontendRequestsAreStateful::class,\n            ],\n        ];\n}\n```\n\n执行数据迁移，数据填充\n\n```\nphp artisan migrate\n\nphp artisan db:seed --class=\"Moell\\Mojito\\Database\\MojitoTableSeeder\"\n```\n\n后台登录的账号 `admin` , 密码 `secret`\n\n## 路由中间件\n\n* auth:sanctum 用于鉴权\n* mojito.permission 权限验证\n\n## mojito.php 可选配置\n\n```php\nreturn [\n    'guards' => [\n        // laravel-permission 相对应的 guard\n        'admin' => [\n            'model' => \\Moell\\Mojito\\Models\\AdminUser::class, //登录鉴权的模型\n            'login_fields' => [\t// 登录验证的字段，支持多个\n                'username',\n            ],\n            'conditions' => [ // 登录验证的额外条件\n                ['status', '=', 1]\n            ]\n        ]\n    ],\n    'route_prefix' => \"api\", //路由前缀\n    \n    'middleware' => [\n        'basic' => 'api', //基础中间件\n\n        'auth' => ['auth:sanctum'], //鉴权中间件\n\n        'permission' => ['auth:sanctum', 'mojito.permission'] //包含权限检测的中间件\n    ]\n];\n```\n\n## 依赖扩展包\n\n* spatie/laravel-permission\n* laravel/sanctum\n\n## 常见错误\n\n* csrf token missing or incorrect ， 请修改 sanctum.php 中的 `stateful` , 如 vite 使用的 `localhost:3000 `去除即可。更多详细请访问`laravel/sanctum`文档。\n\n\n## 打赏\n\n<p>\n  <img src=\"http://ww1.sinaimg.cn/mw690/7a679ca1ly1fvxrfnvxa4j20dw0dwdic.jpg\" width=\"250\" />\n  <img src=\"http://ww1.sinaimg.cn/mw690/7a679ca1ly1fvxrfnr0dhj20dw0dwgp0.jpg\" width=\"250\" />\n</p>\n\n## License\n\nApache License Version 2.0 see http://www.apache.org/licenses/LICENSE-2.0.html\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"moell/mojito\",\n    \"description\": \"Mojito admin is a component of laravel, vue, element build backend system.\",\n    \"keywords\": [\"laravel\", \"admin\", \"vue\", \"element\", \"laravel admin\", \"vue admin\", \"element admin\"],\n    \"type\": \"library\",\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"moell\",\n            \"email\": \"moell91@foxmail.com\"\n        }\n    ],\n    \"require\": {\n        \"php\": \"^7.2|^8.0\",\n        \"spatie/laravel-permission\": \"^5.3\",\n        \"laravel/sanctum\": \"^2.4|^3.2\",\n        \"gregwar/captcha\": \"^1.1\"\n    },\n    \"require-dev\": {\n        \"mockery/mockery\": \"^1.0\",\n        \"orchestra/testbench\": \"^5.0|^6.0|^7.0|^8.0\",\n        \"dms/phpunit-arraysubset-asserts\": \"^0.4.0\",\n        \"doctrine/dbal\": \"^2.8\",\n        \"laravel/legacy-factories\": \"^1.0.4\"\n    },\n    \"autoload\": {\n        \"psr-4\": {\n            \"Moell\\\\Mojito\\\\\": \"src/\"\n        },\n        \"files\": [\n            \"src/helpers.php\"\n        ]\n    },\n    \"autoload-dev\": {\n        \"psr-4\": {\n            \"Moell\\\\Mojito\\\\Tests\\\\\": \"tests/\"\n        }\n    },\n    \"extra\": {\n        \"laravel\": {\n            \"providers\": [\n                \"Moell\\\\Mojito\\\\Providers\\\\MojitoServiceProvider\"\n            ]\n        }\n    },\n    \"minimum-stability\":\"dev\",\n    \"prefer-stable\": true\n}\n"
  },
  {
    "path": "config/mojito.php",
    "content": "<?php\n\nreturn [\n    'guards' => [\n        'admin' => [\n            'model' => \\Moell\\Mojito\\Models\\AdminUser::class,\n            'login_fields' => [\n                'username',\n            ],\n            'conditions' => [\n                ['status', '=', 1]\n            ]\n        ]\n    ],\n\n    'route_prefix' => \"api\",\n\n    'middleware' => [\n        'basic' => 'api',\n\n        'auth' => ['auth:sanctum'],\n\n        'permission' => ['auth:sanctum', 'mojito.permission']\n    ],\n\n    'captcha_cache_ttl' => 2,\n];"
  },
  {
    "path": "database/migrations/add_custom_field_permission_tables.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nclass AddCustomFieldPermissionTables extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        $tableNames = config('permission.table_names');\n\n        Schema::table($tableNames['permissions'], function (Blueprint $table) {\n            $table->integer('pg_id')->default(0);\n            $table->string('display_name', 50)->nullable();\n            $table->string('icon', 30)->nullable();\n            $table->smallInteger('sequence')->nullable();\n            $table->string('created_name', 50)->nullable();\n            $table->string('updated_name', 50)->nullable();\n            $table->string('description')->nullable();\n        });\n\n        Schema::table($tableNames['roles'], function (Blueprint $table) {\n            $table->string('description')->nullable();\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        $tableNames = config('permission.table_names');\n\n        Schema::table($tableNames['permissions'], function (Blueprint $table) {\n            $table->dropColumn('display_name');\n            $table->dropColumn('icon');\n            $table->dropColumn('sequence');\n            $table->dropColumn('created_name');\n            $table->dropColumn('updated_name');\n            $table->dropColumn('description');\n        });\n\n        Schema::table($tableNames['roles'], function (Blueprint $table) {\n            $table->dropColumn('description');\n        });\n    }\n}\n"
  },
  {
    "path": "database/migrations/create_admin_table.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nclass CreateAdminTable extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::create('admin_users', function (Blueprint $table) {\n            $table->increments('id');\n            $table->string('name');\n            $table->string('username')->unique();\n            $table->string('password');\n            $table->boolean(\"status\");\n            $table->rememberToken();\n            $table->timestamps();\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        Schema::dropIfExists('admin_users');\n    }\n}\n"
  },
  {
    "path": "database/migrations/create_menu_table.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nclass CreateMenuTable  extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::create('menus', function (Blueprint $table) {\n            $table->increments('id');\n            $table->integer('parent_id')->default(0);\n            $table->string('icon', 50)->nullable();\n            $table->string('uri');\n            $table->tinyInteger('is_link')->default(0)->comment('0-no;1-yes');\n            $table->string('permission_name', 50)->nullable();\n            $table->string('name');\n            $table->string('guard_name', 30);\n            $table->smallInteger('sequence')->default(0);\n            $table->timestamps();\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        Schema::dropIfExists('menus');\n    }\n}"
  },
  {
    "path": "database/migrations/create_permission_group_table.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nclass CreatePermissionGroupTable  extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::create('permission_groups', function (Blueprint $table) {\n            $table->increments('id');\n            $table->string('name');\n            $table->timestamps();\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        Schema::dropIfExists('permission_groups');\n    }\n}"
  },
  {
    "path": "phpunit.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit bootstrap=\"vendor/autoload.php\"\n         backupGlobals=\"false\"\n         backupStaticAttributes=\"false\"\n         colors=\"true\"\n         verbose=\"true\"\n         convertErrorsToExceptions=\"true\"\n         convertNoticesToExceptions=\"true\"\n         convertWarningsToExceptions=\"true\"\n         processIsolation=\"false\"\n         stopOnFailure=\"false\">\n    <testsuites>\n        <testsuite name=\"Feature\">\n            <directory suffix=\"Test.php\">./tests/Feature</directory>\n        </testsuite>\n\n        <testsuite name=\"Unit\">\n            <directory suffix=\"Test.php\">./tests/Unit</directory>\n        </testsuite>\n    </testsuites>\n    <filter>\n        <whitelist>\n            <directory suffix=\".php\">src/</directory>\n        </whitelist>\n    </filter>\n    <php>\n        <env name=\"DB_CONNECTION\" value=\"testing\"/>\n        <env name=\"APP_KEY\" value=\"AckfSECXIvnK5r28GVIWUAxmbBSjTsmF\"/>\n    </php>\n</phpunit>\n"
  },
  {
    "path": "src/AdminUserFactory.php",
    "content": "<?php\n\nnamespace Moell\\Mojito;\n\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass AdminUserFactory\n{\n    /**\n     * @return Model\n     */\n    public static function adminUser()\n    {\n        return app(config('mojito.guards.admin.model'));\n    }\n}"
  },
  {
    "path": "src/Console/InstallCommand.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Console;\n\nuse Illuminate\\Console\\Command;\n\nclass InstallCommand extends Command\n{\n    /**\n     * The name and signature of the console command.\n     *\n     * @var string\n     */\n    protected $signature = 'mojito:install';\n\n    /**\n     * The console command description.\n     *\n     * @var string\n     */\n    protected $description = 'Run the commands necessary to prepare Mojito for use';\n\n    /**\n     * Execute the console command.\n     *\n     * @author moell<moel91@foxmail.com>\n     * @return mixed\n     */\n    public function handle()\n    {\n        $this->call('vendor:publish', ['--provider' => 'Spatie\\Permission\\PermissionServiceProvider']);\n        $this->call('vendor:publish', ['--provider' => 'Moell\\Mojito\\Providers\\MojitoServiceProvider']);\n        $this->call('vendor:publish', ['--provider' => 'Laravel\\Sanctum\\SanctumServiceProvider']);\n    }\n}\n"
  },
  {
    "path": "src/Contacts/UserContact.php",
    "content": "<?php\n\n\nnamespace Moell\\Mojito\\Contacts;\n\n\ninterface UserContact\n{\n    public function guardName();\n}"
  },
  {
    "path": "src/Database/MojitoTableSeeder.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Database;\n\nuse Illuminate\\Database\\Seeder;\nuse Moell\\Mojito\\AdminUserFactory;\nuse Moell\\Mojito\\Models\\Menu;\nuse Moell\\Mojito\\Models\\PermissionGroup;\nuse Spatie\\Permission\\Models\\Permission;\nuse Spatie\\Permission\\Models\\Role;\n\nclass MojitoTableSeeder extends Seeder\n{\n    private $permissions = [\n        [\n            'name' => 'admin-user.index',\n            'display_name' => '列表',\n            'pg_id' => 1\n        ],\n        [\n            'name' => 'admin-user.show',\n            'display_name' => '详细',\n            'pg_id' => 1\n        ],\n        [\n            'name' => 'admin-user.store',\n            'display_name' => '添加',\n            'pg_id' => 1\n        ],\n        [\n            'name' => 'admin-user.update',\n            'display_name' => '修改',\n            'pg_id' => 1\n        ],\n        [\n            'name' => 'admin-user.destroy',\n            'display_name' => '删除',\n            'pg_id' => 1\n        ],\n        [\n            'name' => 'admin-user.roles',\n            'display_name' => '用户角色列表',\n            'pg_id' => 1\n        ],\n        [\n            'name' => 'admin-user.assign-roles',\n            'display_name' => '分配角色',\n            'pg_id' => 1\n        ],\n        [\n            'name' => 'role.index',\n            'display_name' => '列表',\n            'pg_id' => 2\n        ],\n        [\n            'name' => 'role.show',\n            'display_name' => '详细',\n            'pg_id' => 2\n        ],\n        [\n            'name' => 'role.store',\n            'display_name' => '添加',\n            'pg_id' => 2\n        ],\n        [\n            'name' => 'role.update',\n            'display_name' => '修改',\n            'pg_id' => 2\n        ],\n        [\n            'name' => 'role.destroy',\n            'display_name' => '删除',\n            'pg_id' => 2\n        ],\n        [\n            'name' => 'role.permissions',\n            'display_name' => '获取角色的权限',\n            'pg_id' => 2\n        ],\n        [\n            'name' => 'role.assign-permissions',\n            'display_name' => '角色分配权限',\n            'pg_id' => 2\n        ],\n        [\n            'name' => 'role.guard-name-roles',\n            'display_name' => '看守器对应的所有角色',\n            'pg_id' => 2\n        ],\n        [\n            'name' => 'permission.index',\n            'display_name' => '列表',\n            'pg_id' => 3\n        ],\n        [\n            'name' => 'permission.show',\n            'display_name' => '详细',\n            'pg_id' => 3\n        ],\n        [\n            'name' => 'permission.store',\n            'display_name' => '添加',\n            'pg_id' => 3\n        ],\n        [\n            'name' => 'permission.update',\n            'display_name' => '修改',\n            'pg_id' => 3\n        ],\n        [\n            'name' => 'permission.destroy',\n            'display_name' => '删除',\n            'pg_id' => 3\n        ],\n        [\n            'name' => 'menu.index',\n            'display_name' => '列表',\n            'pg_id' => 4\n        ],\n        [\n            'name' => 'menu.show',\n            'display_name' => '详细',\n            'pg_id' => 4\n        ],\n        [\n            'name' => 'menu.store',\n            'display_name' => '添加',\n            'pg_id' => 4\n        ],\n        [\n            'name' => 'menu.update',\n            'display_name' => '修改',\n            'pg_id' => 4\n        ],\n        [\n            'name' => 'menu.destroy',\n            'display_name' => '删除',\n            'pg_id' => 4\n        ],\n        [\n            'name' => 'permission-group.index',\n            'display_name' => '列表',\n            'pg_id' => 5\n        ],\n        [\n            'name' => 'permission-group.show',\n            'display_name' => '详细',\n            'pg_id' => 5\n        ],\n        [\n            'name' => 'permission-group.store',\n            'display_name' => '添加',\n            'pg_id' => 5\n        ],\n        [\n            'name' => 'permission-group.update',\n            'display_name' => '修改',\n            'pg_id' => 5\n        ],\n        [\n            'name' => 'permission-group.destroy',\n            'display_name' => '删除',\n            'pg_id' => 5\n        ],\n        [\n            'name' => 'permission-group.guard-name-for-permission',\n            'display_name' => '获取看守器权限',\n            'pg_id' => 5\n        ],\n        [\n            'name' => 'permission-group.all',\n            'display_name' => '所有权限组',\n            'pg_id' => 5\n        ]\n    ];\n\n    /**\n     * Run the database seeds.\n     *\n     * @author moell<moel91@foxmail.com>\n     * @return void\n     */\n    public function run()\n    {\n        app()['cache']->forget('spatie.permission.cache');\n\n        $this->createdAdminUser();\n\n        $this->createPermissionGroup();\n\n        $this->createRole();\n\n        $this->createPermission();\n\n        $this->createMenu();\n\n        $this->associateRolePermissions();\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     */\n    private function createdAdminUser()\n    {\n        AdminUserFactory::adminUser()->truncate();\n\n        AdminUserFactory::adminUser()->create([\n            'name' => 'admin',\n            'username' => 'admin',\n            'status' => 1,\n            'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret\n        ]);\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     */\n    private function createPermission()\n    {\n        Permission::query()->delete();\n\n        foreach ($this->permissions as $permission) {\n            $permission['guard_name'] = 'admin';\n            Permission::create($permission);\n        }\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     */\n    private function createPermissionGroup()\n    {\n        PermissionGroup::truncate();\n        PermissionGroup::insert([\n            [\n                'id'    => 1,\n                'name'  => '管理员',\n            ], [\n                'id'    => 2,\n                'name'  => '角色'\n            ], [\n                'id'    => 3,\n                'name'  => '权限'\n            ], [\n                'id'    => 4,\n                'name'  => '菜单'\n            ], [\n                'id'    => 5,\n                'name'  => '权限组'\n            ]\n        ]);\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     */\n    private function createRole()\n    {\n        Role::query()->delete();\n        Role::create([\n            'name' => 'admin',\n            'guard_name' => 'admin'\n        ]);\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     */\n    private function createMenu()\n    {\n        Menu::truncate();\n        Menu::insert([\n            [\n                'id'        => 1,\n                'parent_id' => 0,\n                'uri'       => '/dashboard',\n                'name'      => 'Dashboard',\n                'icon'      => 'Orange',\n                'guard_name'=> 'admin'\n            ],\n            [\n                'id'        => 2,\n                'parent_id' => 0,\n                'uri'       => '/admin',\n                'name'      => '系统管理',\n                'icon'      => 'Setting',\n                'guard_name'=> 'admin'\n            ],\n            [\n                'id'        => 3,\n                'parent_id' => 2,\n                'uri'       => '/admin-user',\n                'name'      => '管理员',\n                'icon'      => '',\n                'guard_name'=> 'admin'\n            ],\n            [\n                'id'        => 4,\n                'parent_id' => 2,\n                'uri'       => '/role',\n                'name'      => '角色',\n                'icon'      => '',\n                'guard_name'=> 'admin'\n            ],\n            [\n                'id'        => 5,\n                'parent_id' => 2,\n                'uri'       => '/permission',\n                'name'      => '权限',\n                'icon'      => '',\n                'guard_name'=> 'admin'\n            ],\n            [\n                'id'        => 6,\n                'parent_id' => 2,\n                'uri'       => '/menu',\n                'name'      => '菜单',\n                'icon'      => '',\n                'guard_name'=> 'admin'\n            ],\n\n        ]);\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     */\n    private function associateRolePermissions()\n    {\n        $role = Role::first();\n\n        AdminUserFactory::adminUser()->first()->assignRole($role->name);\n\n        foreach ($this->permissions as $permission) {\n            $role->givePermissionTo($permission['name']);\n        }\n    }\n}\n"
  },
  {
    "path": "src/Http/Controllers/AdminUserController.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Controllers;\n\n\nuse Illuminate\\Http\\Request;\nuse Auth;\nuse Illuminate\\Http\\Response;\nuse Moell\\Mojito\\AdminUserFactory;\nuse Moell\\Mojito\\Http\\Requests\\AdminUser\\CreateOrUpdateRequest;\nuse Moell\\Mojito\\Resources\\AdminUser as AdminUserResource;\nuse Moell\\Mojito\\Resources\\AdminUserCollection;\nuse Moell\\Mojito\\Resources\\RoleCollection;\n\nclass AdminUserController extends Controller\n{\n    /**\n     * @var \\Illuminate\\Database\\Eloquent\\Model\n     */\n    protected $adminUserModel;\n\n    public function __construct()\n    {\n        $this->adminUserModel = AdminUserFactory::adminUser();\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     * @param Request $request\n     * @return AdminUserCollection\n     */\n    public function index(Request $request)\n    {\n        return new AdminUserCollection($this->adminUserModel->where(request_intersect(['name', 'username']))->paginate());\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     * @param $id\n     * @return AdminUserResource\n     */\n    public function show($id)\n    {\n        return new AdminUserResource($this->adminUserModel->findOrFail($id));\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     * @param CreateOrUpdateRequest $request\n     * @return Response\n     */\n    public function store(CreateOrUpdateRequest $request)\n    {\n        $data = request_intersect([\n            'name', 'username', 'password'\n        ]);\n        $data['status'] = $request->status ? true : false;\n        $data['password'] = bcrypt($data['password']);\n\n        $this->adminUserModel->create($data);\n\n        return $this->created();\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     * @param CreateOrUpdateRequest $request\n     * @param $id\n     * @return Response\n     */\n    public function update(CreateOrUpdateRequest $request, $id)\n    {\n        $adminUser = $this->adminUserModel->findOrFail($id);\n\n        $data = $request->only([\n            'name', 'status'\n        ]);\n\n        if ($request->filled('password')) {\n            $data['password'] = bcrypt($request->password);\n        }\n\n        $adminUser->fill($data);\n        $adminUser->save();\n\n        return $this->noContent();\n    }\n\n    /**\n     * @author moell<moel91@foxmail.com>\n     * @param $id\n     * @return Response\n     */\n    public function destroy($id)\n    {\n        $adminUser = $this->adminUserModel->findOrFail($id);\n\n        $adminUser->delete();\n\n        return $this->noContent();\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param $id\n     * @param $provider\n     * @return RoleCollection\n     */\n    public function roles($id, $provider)\n    {\n        $user = $this->getGuardModel($provider)->findOrFail($id);\n\n        return new RoleCollection($user->roles);\n    }\n\n    /**\n     * @param $id\n     * @param $guard\n     * @param Request $request\n     * @return Response\n     *@author moell<moell91@foxmail.com>\n     */\n    public function assignRoles($id, $guard, Request $request)\n    {\n        $user = $this->getGuardModel($guard)->findOrFail($id);\n\n        $user->syncRoles($request->input('roles', []));\n\n        return $this->noContent();\n    }\n\n    /**\n     * @param $guard\n     * @return Illuminate\\Foundation\\Auth\\User\n     */\n    private function getGuardModel($guard)\n    {\n        return app(config('mojito.guards.' . $guard . '.model'));\n    }\n}\n"
  },
  {
    "path": "src/Http/Controllers/CaptchaController.php",
    "content": "<?php\n\n\nnamespace Moell\\Mojito\\Http\\Controllers;\n\n\nuse Gregwar\\Captcha\\CaptchaBuilder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Illuminate\\Support\\Str;\n\nclass CaptchaController extends Controller\n{\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param CaptchaBuilder $captchaBuilder\n     * @return \\Illuminate\\Http\\JsonResponse\n     */\n    public function generate(CaptchaBuilder $captchaBuilder)\n    {\n        $key = Str::uuid()->toString();\n\n        $captcha = $captchaBuilder->build();\n        $expiredAt = Carbon::now()->addMinutes(config(\"mojito.captcha_cache_ttl\", 2));\n\n        Cache::put($key, ['code' => $captcha->getPhrase()], $expiredAt);\n\n        return $this->success([\n            'data' => [\n                'key' => $key,\n                'expired_at' => $expiredAt->toDateTimeString(),\n                'image_content' => $captcha->inline()\n            ]\n        ]);\n    }\n}"
  },
  {
    "path": "src/Http/Controllers/ChangePasswordController.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Controllers;\n\n\nuse Auth;\nuse Hash;\nuse Moell\\Mojito\\Http\\Requests\\ChangePasswordRequest;\n\nclass ChangePasswordController extends Controller\n{\n    /**\n     * @author moell\n     * @param ChangePasswordRequest $request\n     * @return \\Illuminate\\Http\\JsonResponse|\\Illuminate\\Http\\Response\n     */\n    public function changePassword(ChangePasswordRequest $request)\n    {\n        $user = Auth::user();\n\n        if (! Hash::check($request->old_password, $user->password)) {\n            return $this->unprocesableEtity([\n                'password' => 'Incorrect password'\n            ]);\n        }\n\n        $user->password = bcrypt($request->password);\n        $user->save();\n\n        return $this->noContent();\n    }\n}"
  },
  {
    "path": "src/Http/Controllers/Controller.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Controllers;\n\nuse Illuminate\\Foundation\\Bus\\DispatchesJobs;\nuse Illuminate\\Routing\\Controller as BaseController;\nuse Illuminate\\Foundation\\Validation\\ValidatesRequests;\nuse Illuminate\\Foundation\\Auth\\Access\\AuthorizesRequests;\nuse Moell\\Mojito\\Http\\MojitoResponse;\n\nclass Controller extends BaseController\n{\n    use AuthorizesRequests, DispatchesJobs, ValidatesRequests, MojitoResponse;\n}"
  },
  {
    "path": "src/Http/Controllers/LoginController.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Controllers;\n\n\nuse App\\Member;\nuse App\\User;\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Support\\Facades\\Auth;\nuse Illuminate\\Support\\Facades\\Cache;\nuse Illuminate\\Support\\Facades\\Hash;\nuse Illuminate\\Validation\\ValidationException;\nuse Laravel\\Sanctum\\PersonalAccessToken;\nuse Moell\\Mojito\\Models\\AdminUser;\n\nclass LoginController extends Controller\n{\n    public function authenticate(Request $request)\n    {\n        $config = data_get(config(\"mojito.guards\"), $request->guard);\n\n        if (! $config) {\n            return $this->forbidden(\"Undefined guard\");\n        }\n\n        $cacheCaptcha = Cache::get($request->captcha_key);\n        if (! $cacheCaptcha) {\n            return $this->forbidden('Verification code has expired');\n        }\n\n        if (strtolower($cacheCaptcha['code']) != strtolower($request->captcha)) {\n            return $this->forbidden('Please enter correct verify code');\n        }\n\n        Cache::forget($request->captcha_key);\n\n        $conditions = data_get($config, 'conditions', []);\n\n        $user = app($config['model'])->where(function ($query) use ($config) {\n            foreach ($config['login_fields'] as $field) {\n                $query->orWhere($field, request()->get('username'));\n            }\n            return $query;\n        })->when($conditions, function ($query) use ($conditions) {\n            return $query->where($conditions);\n        })->first();\n\n        if (! $user || ! Hash::check($request->password, $user->password)) {\n            throw ValidationException::withMessages([\n                'username' => ['The provided credentials are incorrect.'],\n            ]);\n        }\n\n        PersonalAccessToken::query()->where(\"tokenable_type\", $config['model'])\n            ->where(\"name\", $request->guard)\n            ->where(\"tokenable_id\", $user->id)\n            ->delete();\n\n        return response()->json([\n            'data' => [\n                'token' => $user->createToken($request->guard)->plainTextToken,\n            ]\n        ]);\n    }\n\n    /**\n     * logout\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function logout()\n    {\n        Auth::user()->currentAccessToken()->delete();\n\n        return $this->noContent();\n    }\n}"
  },
  {
    "path": "src/Http/Controllers/MenuController.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Controllers;\n\n\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Support\\Facades\\Auth;\nuse Moell\\Mojito\\Http\\Requests\\Menu\\CreateOrUpdateRequest;\nuse Moell\\Mojito\\Models\\Menu;\nuse Moell\\Mojito\\Resources\\Menu as MenuResource;\n\nclass MenuController extends Controller\n{\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param Request $request\n     * @return \\Illuminate\\Http\\JsonResponse\n     */\n    public function index(Request $request)\n    {\n        $menus = Menu::query()\n            ->where('guard_name', $request->input('guard_name', 'admin'))\n            ->orderBy('sequence', 'desc')\n            ->get();\n\n        return response()->json(['data' => make_tree($menus->toArray())]);\n    }\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param CreateOrUpdateRequest $request\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function store(CreateOrUpdateRequest $request)\n    {\n        Menu::create($request->all());\n\n        return $this->created();\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @return \\Illuminate\\Http\\JsonResponse\n     */\n    public function my(Request $request)\n    {\n        $guardName = data_get(Auth::user()->currentAccessToken(), \"name\", \"admin\");\n\n        $userPermissions = Auth::user()->getAllPermissions()->pluck('name');\n        $menus = Menu::query()\n            ->where('guard_name', $guardName)\n            ->orderBy('sequence', 'desc')\n            ->get()\n            ->filter(function ($item) use ($userPermissions) {\n                return !$item->permission_name || $userPermissions->contains($item->permission_name);\n            });\n\n        return response()->json(['data' => make_tree($menus->toArray())]);\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param CreateOrUpdateRequest $request\n     * @param $id\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function update(CreateOrUpdateRequest $request, $id)\n    {\n        $menu = Menu::query()->findOrFail($id);\n\n        $menu->update($request->toArray());\n\n        return $this->noContent();\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param $id\n     * @return MenuResource\n     */\n    public function show($id)\n    {\n        return new MenuResource(Menu::query()->findOrFail($id));\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param $id\n     * @return \\Illuminate\\Http\\JsonResponse|\\Illuminate\\Http\\Response\n     */\n    public function destroy($id)\n    {\n        $menu = Menu::query()->findOrFail($id);\n\n        if (Menu::query()->where('parent_id', $menu->id)->count()) {\n            return $this->unprocesableEtity([\n                'parent_id' => 'Please delete the submenu first.'\n            ]);\n        }\n\n        $menu->delete();\n\n        return $this->noContent();\n    }\n}"
  },
  {
    "path": "src/Http/Controllers/PermissionController.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Controllers;\n\n\nuse Illuminate\\Http\\Request;\nuse Moell\\Mojito\\Http\\Requests\\Permission\\CreateOrUpdateRequest;\nuse Moell\\Mojito\\Resources\\PermissionCollection;\nuse Spatie\\Permission\\Exceptions\\PermissionAlreadyExists;\nuse Moell\\Mojito\\Models\\Permission;\nuse Moell\\Mojito\\Resources\\Permission as PermissionResource;\nuse Auth;\n\nclass PermissionController extends Controller\n{\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param Request $request\n     * @return PermissionCollection\n     */\n    public function index(Request $request)\n    {\n        $permissions =tap(Permission::latest(), function ($query) {\n            $query->where(request_intersect([\n                'name', 'guard_name', 'pg_id'\n            ]));\n        })->with('group')->paginate();\n\n        return new PermissionCollection($permissions);\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param $id\n     * @return PermissionResource\n     */\n    public function show($id)\n    {\n        return new PermissionResource(Permission::query()->findOrFail($id));\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param CreateOrUpdateRequest $request\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function store(CreateOrUpdateRequest $request)\n    {\n        $attributes = $request->only([\n            'pg_id', 'name', 'guard_name', 'display_name', 'icon', 'sequence', 'description'\n        ]);\n        $attributes['created_name'] = Auth::user()->name;\n\n        Permission::create($attributes);\n\n        return $this->created();\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param CreateOrUpdateRequest $request\n     * @param $id\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function update(CreateOrUpdateRequest $request, $id)\n    {\n        $permission = Permission::query()->findOrFail($id);\n\n        $attributes = $request->only([\n            'pg_id', 'name', 'guard_name', 'display_name', 'icon', 'sequence', 'description'\n        ]);\n\n        $attributes['updated_name'] = Auth::user()->name;\n\n        $isset = Permission::query()\n            ->where(['name' => $attributes['name'], 'guard_name' => $attributes['guard_name']])\n            ->where('id', '!=', $id)\n            ->count();\n\n        if ($isset) {\n            throw PermissionAlreadyExists::create($attributes['name'], $attributes['guard_name']);\n        }\n\n        $permission->update($attributes);\n\n        return $this->noContent();\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param $id\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function destroy($id)\n    {\n        permission::query()->findOrFail($id)->delete();\n\n        return $this->noContent();\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @return \\Illuminate\\Http\\JsonResponse\n     */\n    public function allUserPermission()\n    {\n        return response()->json(['data' => Auth::user()->getAllPermissions()->pluck('name')]);\n    }\n}"
  },
  {
    "path": "src/Http/Controllers/PermissionGroupController.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Controllers;\n\n\nuse Illuminate\\Http\\Request;\nuse Moell\\Mojito\\Http\\Requests\\PermissionGroup\\CreateOrUpdateRequest;\nuse Moell\\Mojito\\Models\\PermissionGroup;\nuse Moell\\Mojito\\Models\\Permission;\nuse Moell\\Mojito\\Resources\\PermissionGroupCollection;\nuse Moell\\Mojito\\Resources\\PermissionGroup as PermissionGroupResource;\n\nclass PermissionGroupController extends Controller\n{\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param Request $request\n     * @return PermissionGroupCollection\n     */\n    public function index(Request $request)\n    {\n        $permissionGroups = tap(PermissionGroup::latest(), function ($query) {\n            $query->where(request_intersect(['name']));\n        })->paginate();\n\n        return new PermissionGroupCollection($permissionGroups);\n    }\n\n    /**\n     *  @author moell<moell91@foxmail.com>\n     * @param Request $request\n     * @return PermissionGroupCollection\n     */\n    public function all(Request $request)\n    {\n        $permissionGroups = PermissionGroup::latest()->get();\n\n        return new PermissionGroupCollection($permissionGroups);\n    }\n\n    /**\n     * @param $guardName\n     * @return \\Illuminate\\Http\\JsonResponse\n     */\n    public function guardNameForPermissions($guardName)\n    {\n        $permissionGroups = PermissionGroup::query()\n            ->with(['permission' => function ($query) use ($guardName) {\n                $query->where('guard_name', $guardName);\n            }])\n            ->get()->filter(function($item)  {\n                return count($item->permission) > 0;\n            });\n\n        return response()->json([\n            'data' => array_values($permissionGroups->toArray())\n        ]);\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param CreateOrUpdateRequest $request\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function store(CreateOrUpdateRequest $request)\n    {\n        PermissionGroup::create(request_intersect(['name']));\n\n        return $this->created();\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param $id\n     * @return PermissionGroupResource\n     */\n    public function show($id)\n    {\n        return new PermissionGroupResource(PermissionGroup::findOrFail($id));\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param CreateOrUpdateRequest $request\n     * @param $id\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function update(CreateOrUpdateRequest $request, $id)\n    {\n        PermissionGroup::findOrFail($id)->update(request_intersect([\n            'name'\n        ]));\n\n        return $this->noContent();\n    }\n\n    /**\n     * @param $id\n     * @return \\Illuminate\\Http\\JsonResponse|\\Illuminate\\Http\\Response\n     */\n    public function destroy($id)\n    {\n        $permissionGroup = PermissionGroup::findOrFail($id);\n\n        if (Permission::query()->where('pg_id', $permissionGroup->id)->count()) {\n            return $this->unprocesableEtity([\n                'pg_id' => 'Please move or delete the vesting permission.'\n            ]);\n        }\n\n        $permissionGroup->delete();\n\n        return $this->noContent();\n    }\n}"
  },
  {
    "path": "src/Http/Controllers/RoleController.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Controllers;\n\nuse Auth;\nuse Illuminate\\Http\\Request;\nuse Moell\\Mojito\\Http\\Requests\\Role\\CreateOrUpdateRequest;\nuse Moell\\Mojito\\Resources\\PermissionCollection;\nuse Moell\\Mojito\\Resources\\RoleCollection;\nuse Moell\\Mojito\\Resources\\Role as RoleResource;\nuse Spatie\\Permission\\Exceptions\\RoleAlreadyExists;\nuse Spatie\\Permission\\Models\\Role;\n\nclass RoleController extends Controller\n{\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param Request $request\n     * @return RoleCollection\n     */\n    public function index(Request $request)\n    {\n        return new RoleCollection(Role::query()->where(request_intersect(['name']))->paginate());\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param $guardName\n     * @return RoleCollection\n     */\n    public function guardNameRoles($guardName)\n    {\n        return new RoleCollection(Role::query()->where('guard_name', $guardName)->get());\n    }\n\n    public function show($id)\n    {\n        return new RoleResource(Role::query()->findOrFail($id));\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param CreateOrUpdateRequest $request\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function store(CreateOrUpdateRequest $request)\n    {\n        Role::create(request_intersect([\n            'name', 'guard_name', 'description'\n        ]));\n\n        return $this->created();\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param CreateOrUpdateRequest $request\n     * @param $id\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function update(CreateOrUpdateRequest $request, $id)\n    {\n        if (Role::where(request_intersect(['name', 'guard_name']))->where('id', '!=', $id)->count()) {\n            throw RoleAlreadyExists::create($request->name, $request->guard_name);\n        }\n\n        $role = Role::query()->findOrFail($id);\n\n        $role->update(request_intersect([\n            'name', 'guard_name', 'description'\n        ]));\n\n        return $this->noContent();\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param $id\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function destroy($id)\n    {\n        Role::destroy($id);\n\n        return $this->noContent();\n    }\n\n    /**\n     * @author moell<moell91@foxmail.com>\n     * @param $id\n     * @return PermissionCollection\n     */\n    public function permissions($id)\n    {\n        $role = Role::query()->findOrFail($id);\n\n        return new PermissionCollection($role->permissions);\n    }\n\n    /**\n     * Assign permission\n     *\n     * @author moell<moell91@foxmail.com>\n     * @param $id\n     * @param Request $request\n     * @return \\Illuminate\\Http\\Response\n     */\n    public function assignPermissions($id, Request $request)\n    {\n        $role = Role::query()->findOrFail($id);\n\n        $role->syncPermissions($request->input('permissions', []));\n\n        return $this->noContent();\n    }\n}"
  },
  {
    "path": "src/Http/Middleware/Authenticate.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Middleware;\n\nuse Illuminate\\Support\\Facades\\Auth;\nuse Illuminate\\Support\\Facades\\Route;\nuse Spatie\\Permission\\Exceptions\\UnauthorizedException;\n\nclass Authenticate\n{\n    /**\n     * @author moell<moel91@foxmail.com>\n     * @param $request\n     * @param \\Closure $next\n     * @return mixed\n     */\n    public function handle($request, \\Closure $next)\n    {\n        $permission = Route::currentRouteName();\n\n        if (Auth::user()->hasPermissionTo($permission)) {\n            return $next($request);\n        }\n\n        throw UnauthorizedException::forPermissions([$permission]);\n    }\n}"
  },
  {
    "path": "src/Http/MojitoResponse.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http;\n\nuse Illuminate\\Http\\Response;\n\ntrait MojitoResponse\n{\n    /**\n     * 201\n     *\n     * @author moell<moel91@foxmail.com>\n     * @param string $content\n     * @return Response\n     */\n    protected function created($content = '')\n    {\n        return new Response($content, Response::HTTP_CREATED);\n    }\n\n    /**\n     * 202\n     *\n     * @author moell<moel91@foxmail.com>\n     * @return Response\n     */\n    protected function accepted()\n    {\n        return new Response('', Response::HTTP_ACCEPTED);\n    }\n\n    /**\n     * 204\n     *\n     * @author moell<moel91@foxmail.com>\n     * @return Response\n     */\n    protected function noContent()\n    {\n        return new Response('', Response::HTTP_NO_CONTENT);\n    }\n\n    /**\n     * 400\n     *\n     * @author moell<moel91@foxmail.com>\n     * @param $message\n     * @param array $headers\n     * @param int $options\n     * @return \\Illuminate\\Http\\JsonResponse\n     */\n    protected function badRequest($message, array $headers = [], $options = 0)\n    {\n        return response()->json([\n            'message' => $message\n        ], Response::HTTP_BAD_REQUEST, $headers, $options);\n    }\n\n    /**\n     * 401\n     *\n     * @author moell<moel91@foxmail.com>\n     * @param string $message\n     * @param array $headers\n     * @param int $options\n     * @return \\Illuminate\\Http\\JsonResponse\n     */\n    protected function unauthorized($message = '', array $headers = [], $options = 0)\n    {\n        return response()->json([\n            'message' => $message ? $message : 'Token Signature could not be verified.'\n        ], Response::HTTP_UNAUTHORIZED, $headers, $options);\n    }\n\n    /**\n     * 403\n     *\n     * @author moell<moel91@foxmail.com>\n     * @param string $message\n     * @param array $headers\n     * @param int $options\n     * @return \\Illuminate\\Http\\JsonResponse\n     */\n    protected function forbidden($message = '', array $headers = [], $options = 0)\n    {\n        return response()->json([\n            'message' => $message ? $message : 'Insufficient permissions.'\n        ], Response::HTTP_FORBIDDEN, $headers, $options);\n    }\n\n    /**\n     * 422\n     *\n     * @author moell<moel91@foxmail.com>\n     * @param array $errors\n     * @param array $headers\n     * @param string $message\n     * @param int $options\n     * @return \\Illuminate\\Http\\JsonResponse\n     */\n    protected function unprocesableEtity(array $errors = [], array $headers = [], $message = '', $options = 0)\n    {\n        return response()->json([\n            'message' => $message ? $message : '422 Unprocessable Entity',\n            'errors' => $errors\n        ], Response::HTTP_UNPROCESSABLE_ENTITY, $headers, $options);\n    }\n\n    /**\n     * 200\n     *\n     * @author moell<moel91@foxmail.com>\n     * @param array $data\n     * @param array $headers\n     * @param int $options\n     * @return \\Illuminate\\Http\\JsonResponse\n     */\n    protected function success(array $data, array $headers = [], $options = 0)\n    {\n        return response()->json($data, Response::HTTP_OK, $headers, $options);\n    }\n}"
  },
  {
    "path": "src/Http/Requests/AdminUser/CreateOrUpdateRequest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Requests\\AdminUser;\n\n\nuse Illuminate\\Foundation\\Http\\FormRequest;\nuse Moell\\Mojito\\AdminUserFactory;\n\nclass CreateOrUpdateRequest extends FormRequest\n{\n    /**\n     * Determine if the user is authorized to make this request.\n     *\n     * @return bool\n     */\n    public function authorize()\n    {\n        return true;\n    }\n\n    /**\n     * Get the validation rules that apply to the request.\n     *\n     * @author moell<moel91@foxmail.com>\n     * @return array\n     */\n    public function rules()\n    {\n        $rules = [\n            'name' => 'required|max:255'\n        ];\n\n        switch ($this->method()) {\n            case 'POST':\n                $rules['password'] = 'required|min:6|max:32';\n                $rules['username'] = 'required|unique:' . AdminUserFactory::adminUser()->getTable();\n                break;\n            case 'PATCH':\n                $rules['password'] = 'nullable|min:8|max:32';\n                break;\n        }\n\n        return $rules;\n    }\n}"
  },
  {
    "path": "src/Http/Requests/ChangePasswordRequest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Requests;\n\n\nuse Illuminate\\Foundation\\Http\\FormRequest;\n\nclass ChangePasswordRequest extends FormRequest\n{\n    /**\n     * Determine if the user is authorized to make this request.\n     *\n     * @return bool\n     */\n    public function authorize()\n    {\n        return true;\n    }\n\n    /**\n     * Get the validation rules that apply to the request.\n     *\n     * @author moell<moel91@foxmail.com>\n     * @return array\n     */\n    public function rules()\n    {\n        return [\n            'old_password' => 'required|min:6|max:32',\n            'password' => 'required|min:8|max:32|confirmed',\n            'password_confirmation' => 'required|min:8|max:32'\n        ];\n    }\n}"
  },
  {
    "path": "src/Http/Requests/Menu/CreateOrUpdateRequest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Requests\\Menu;\n\n\nuse Illuminate\\Foundation\\Http\\FormRequest;\n\nclass CreateOrUpdateRequest extends FormRequest\n{\n    /**\n     * Determine if the user is authorized to make this request.\n     *\n     * @return bool\n     */\n    public function authorize()\n    {\n        return true;\n    }\n\n    /**\n     * Get the validation rules that apply to the request.\n     *\n     * @author moell<moel91@foxmail.com>\n     * @return array\n     */\n    public function rules()\n    {\n        return [\n            'parent_id' => 'required|numeric',\n            'name' => 'required',\n            'guard_name' => 'required',\n            'is_link' => 'in:0,1',\n            'uri' => 'required'\n        ];\n    }\n}"
  },
  {
    "path": "src/Http/Requests/Permission/CreateOrUpdateRequest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Requests\\Permission;\n\n\nuse Illuminate\\Foundation\\Http\\FormRequest;\nuse Moell\\Mojito\\AdminUserFactory;\n\nclass CreateOrUpdateRequest extends FormRequest\n{\n    /**\n     * Determine if the user is authorized to make this request.\n     *\n     * @return bool\n     */\n    public function authorize()\n    {\n        return true;\n    }\n\n    /**\n     * Get the validation rules that apply to the request.\n     *\n     * @author moell<moel91@foxmail.com>\n     * @return array\n     */\n    public function rules()\n    {\n        $rules = [\n            'name' => 'required|max:255',\n            'guard_name' => 'required|max:255',\n            'display_name' => 'required:max:50',\n            'pg_id' => 'required|numeric',\n            'sequence' => 'numeric'\n        ];\n\n        return $rules;\n    }\n}"
  },
  {
    "path": "src/Http/Requests/PermissionGroup/CreateOrUpdateRequest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Requests\\PermissionGroup;\n\n\nuse Illuminate\\Foundation\\Http\\FormRequest;\n\nclass CreateOrUpdateRequest extends FormRequest\n{\n    /**\n     * Determine if the user is authorized to make this request.\n     *\n     * @return bool\n     */\n    public function authorize()\n    {\n        return true;\n    }\n\n    /**\n     * Get the validation rules that apply to the request.\n     *\n     * @author moell<moel91@foxmail.com>\n     * @return array\n     */\n    public function rules()\n    {\n        $rules = [\n            'name' => 'required|max:255'\n        ];\n\n        return $rules;\n    }\n}"
  },
  {
    "path": "src/Http/Requests/Role/CreateOrUpdateRequest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Http\\Requests\\Role;\n\n\nuse Illuminate\\Foundation\\Http\\FormRequest;\n\nclass CreateOrUpdateRequest extends FormRequest\n{\n    /**\n     * Determine if the user is authorized to make this request.\n     *\n     * @return bool\n     */\n    public function authorize()\n    {\n        return true;\n    }\n\n    /**\n     * Get the validation rules that apply to the request.\n     *\n     * @author moell<moel91@foxmail.com>\n     * @return array\n     */\n    public function rules()\n    {\n        $rules = [\n            'name' => 'required|max:255',\n            'guard_name' => 'required|max:255'\n        ];\n\n        return $rules;\n    }\n}"
  },
  {
    "path": "src/Models/AdminUser.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Models;\n\n\nclass AdminUser extends User\n{\n    protected $guard_name = 'admin';\n\n    /**\n     * The attributes that are mass assignable.\n     *\n     * @var array\n     */\n    protected $fillable = [\n        'name', 'username', 'password', 'status',\n    ];\n\n    /**\n     * The attributes that should be hidden for arrays.\n     *\n     * @var array\n     */\n    protected $hidden = [\n        'password', 'remember_token',\n    ];\n}"
  },
  {
    "path": "src/Models/Menu.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Models;\n\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Menu extends Model\n{\n    protected $fillable = ['parent_id', 'name', 'icon', 'uri', 'is_link', 'guard_name', 'permission_name', 'sequence'];\n}"
  },
  {
    "path": "src/Models/Permission.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Models;\n\n\nclass Permission extends \\Spatie\\Permission\\Models\\Permission\n{\n    public function group()\n    {\n        return $this->belongsTo(PermissionGroup::class, 'pg_id');\n    }\n}"
  },
  {
    "path": "src/Models/PermissionGroup.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Models;\n\n\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass PermissionGroup extends Model\n{\n    protected $guarded = ['id'];\n\n    public function permission()\n    {\n        return $this->hasMany('Moell\\Mojito\\Models\\Permission', 'pg_id');\n    }\n}"
  },
  {
    "path": "src/Models/User.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Models;\n\n\nuse Illuminate\\Notifications\\Notifiable;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\nuse Laravel\\Sanctum\\HasApiTokens;\nuse Moell\\Mojito\\Contacts\\UserContact;\nuse Spatie\\Permission\\Traits\\HasRoles;\n\nclass User extends Authenticatable implements UserContact\n{\n    protected $guard_name;\n\n    use HasApiTokens, Notifiable, HasRoles;\n\n    public function guardName()\n    {\n        return $this->guard_name;\n    }\n\n}"
  },
  {
    "path": "src/Providers/MojitoServiceProvider.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Providers;\n\n\nuse Illuminate\\Support\\ServiceProvider;\nuse Moell\\Mojito\\Console\\InstallCommand;\nuse Route;\n\nclass MojitoServiceProvider extends ServiceProvider\n{\n    /**\n     * Bootstrap any application services.\n     *\n     * @return void\n     */\n    public function boot()\n    {\n        if ($this->app->runningInConsole()) {\n            $this->registerMigrations();\n\n            $this->commands([\n                InstallCommand::class,\n            ]);\n\n            $this->publishes([\n                __DIR__.'/../../config/mojito.php' => config_path('mojito.php'),\n            ], 'config');\n        }\n\n        $this->registerRouter();\n    }\n\n    /**\n     * Register any application services.\n     *\n     * @return void\n     */\n    public function register()\n    {\n        //\n    }\n\n    private function registerMigrations()\n    {\n        $migrationsPath = __DIR__ . '/../../database/migrations/';\n\n        $items = [\n            'create_admin_table.php',\n            'add_custom_field_permission_tables.php',\n            'create_menu_table.php',\n            'create_permission_group_table.php'\n        ];\n\n        $paths = [];\n        foreach ($items as $key => $name) {\n            $paths[$migrationsPath . $name] = database_path('migrations') . \"/\". $this->formatTimestamp($key+1) . '_' . $name;\n        }\n\n        $this->publishes($paths, 'migrations');\n    }\n\n    /**\n     * @param $addition\n     * @return false|string\n     */\n    private function formatTimestamp($addition)\n    {\n        return date('Y_m_d_His', time() + $addition);\n    }\n\n    /**\n     * 注册路由\n     *\n     * @author moell\n     */\n    private function registerRouter()\n    {\n        if (strpos($this->app->version(), 'Lumen') === false && !$this->app->routesAreCached()) {\n            app('router')->middleware('api')->group(__DIR__.'/../routes.php');\n        } else {\n            require __DIR__.'/../routes.php';\n        }\n    }\n}"
  },
  {
    "path": "src/Resources/AdminUser.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Resources;\n\n\nuse Illuminate\\Http\\Resources\\Json\\JsonResource;\n\nclass AdminUser extends JsonResource\n{\n    public function toArray($request)\n    {\n        return [\n            'id'    => $this->id,\n            'name'  => $this->name,\n            'username' => $this->username,\n            'status' => $this->status ? true : false,\n            'created_at' => (string)$this->created_at,\n            'updated_at' => (string)$this->updated_at\n        ];\n    }\n}"
  },
  {
    "path": "src/Resources/AdminUserCollection.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Resources;\n\n\nuse Illuminate\\Http\\Resources\\Json\\ResourceCollection;\n\nclass AdminUserCollection extends ResourceCollection\n{\n    public function toArray($request)\n    {\n        return [\n            'data' => $this->collection\n        ];\n    }\n}"
  },
  {
    "path": "src/Resources/Menu.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Resources;\n\n\nuse Illuminate\\Http\\Resources\\Json\\JsonResource;\n\nclass Menu extends JsonResource\n{\n    public function toArray($request)\n    {\n        return [\n            'id' => $this->id,\n            'name' => $this->name,\n            'guard_name' => $this->guard_name,\n            'icon' => $this->icon,\n            'uri' => $this->uri,\n            'is_link' => $this->is_link,\n            'created_at' => (string)$this->created_at,\n            'updated_at' => (string)$this->updated_at\n        ];\n    }\n}"
  },
  {
    "path": "src/Resources/Permission.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Resources;\n\n\nuse Illuminate\\Http\\Resources\\Json\\JsonResource;\n\nclass Permission extends JsonResource\n{\n    public function toArray($request)\n    {\n        return [\n            'id' => $this->id,\n            'pg_id' => $this->pg_id,\n            'name' => $this->name,\n            'guard_name' => $this->guard_name,\n            'display_name' => $this->display_name,\n            'group' => new PermissionGroup($this->group),\n            'icon' => $this->icon,\n            'sequence' => $this->sequence,\n            'description' => $this->description,\n            'created_name' => $this->created_name,\n            'updated_name' => $this->updated_name,\n            'created_at' => (string)$this->created_at,\n            'updated_at' => (string)$this->created_at\n        ];\n    }\n}"
  },
  {
    "path": "src/Resources/PermissionCollection.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Resources;\n\n\nuse Illuminate\\Http\\Resources\\Json\\ResourceCollection;\n\nclass PermissionCollection extends ResourceCollection\n{\n    public function toArray($request)\n    {\n        return [\n            'data' => $this->collection\n        ];\n    }\n}"
  },
  {
    "path": "src/Resources/PermissionGroup.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Resources;\n\n\nuse Illuminate\\Http\\Resources\\Json\\JsonResource;\n\nclass PermissionGroup extends JsonResource\n{\n    public function toArray($request)\n    {\n        return [\n            'id' => $this->id,\n            'name' => $this->name,\n            'created_at' => (string)$this->created_at,\n            'updated_at' => (string)$this->updated_at\n        ];\n    }\n}"
  },
  {
    "path": "src/Resources/PermissionGroupCollection.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Resources;\n\n\nuse Illuminate\\Http\\Resources\\Json\\ResourceCollection;\n\nclass PermissionGroupCollection extends ResourceCollection\n{\n    public function toArray($request)\n    {\n        return [\n            'data' => $this->collection\n        ];\n    }\n}"
  },
  {
    "path": "src/Resources/Role.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Resources;\n\n\nuse Illuminate\\Http\\Resources\\Json\\JsonResource;\n\nclass Role extends JsonResource\n{\n    public function toArray($request)\n    {\n        return [\n            'id' => $this->id,\n            'name' => $this->name,\n            'guard_name' => $this->guard_name,\n            'description' => $this->description,\n            'created_at' => (string)$this->created_at,\n            'updated_at' => (string)$this->updated_at\n        ];\n    }\n}"
  },
  {
    "path": "src/Resources/RoleCollection.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Resources;\n\n\nuse Illuminate\\Http\\Resources\\Json\\ResourceCollection;\n\nclass RoleCollection extends ResourceCollection\n{\n    public function toArray($request)\n    {\n        return [\n            'data' => $this->collection\n        ];\n    }\n}"
  },
  {
    "path": "src/helpers.php",
    "content": "<?php\n\nif (!function_exists('request_intersect')) {\n    /**\n     * request intersect\n     *\n     * @param $keys\n     * @return array|ø\n     */\n    function request_intersect($keys) {\n        return array_filter(request()->only(is_array($keys) ? $keys : func_get_args()));\n    }\n}\n\nif (!function_exists('make_tree')) {\n    /**\n     * @param array $list\n     * @param int $parentId\n     * @return array\n     */\n    function make_tree(array $list, $parentId = 0) {\n        $tree = [];\n        if (empty($list)) {\n            return $tree;\n        }\n\n        $newList = [];\n        foreach ($list as $k => $v) {\n            $newList[$v['id']] = $v;\n        }\n        \n        foreach ($newList as $value) {\n            if ($parentId == $value['parent_id']) {\n                $tree[] = &$newList[$value['id']];\n            } elseif (isset($newList[$value['parent_id']])) {\n                $newList[$value['parent_id']]['children'][] = &$newList[$value['id']];\n            }\n        }\n\n        return $tree;\n    }\n}"
  },
  {
    "path": "src/routes.php",
    "content": "<?php\n\n$router = app('router');\n\n$router->namespace('\\Moell\\Mojito\\Http\\Controllers')\n    ->prefix(config(\"mojito.route_prefix\", \"api\"))\n    ->middleware(config(\"mojito.middleware.basic\", \"api\"))\n    ->group(function ($router) {\n        $router->post(\"auth/login\", \"LoginController@authenticate\");\n\n        $router->get(\"/captcha\", \"CaptchaController@generate\");\n\n        $router->middleware(config(\"mojito.middleware.auth\", ['auth:sanctum']))->group(function ($router) {\n            $router->post(\"auth/logout\", \"LoginController@logout\")->name(\"auth.logout\");\n            $router->get('permission-user-all', 'PermissionController@allUserPermission')->name(\"permission.all-user-permission\");\n            $router->get('my-menu', 'MenuController@my')->name(\"menu.my\");\n            $router->patch('user-change-password', 'ChangePasswordController@changePassword')->name(\"user.change-password\");\n        });\n\n\n        $router->middleware(config(\"mojito.middleware.permission\", ['auth:sanctum', 'mojito.permission']))\n            ->group(function ($router) {\n                $router->apiResources([\n                    'role' => 'RoleController',\n                    'permission' => 'PermissionController',\n                    'admin-user' => 'AdminUserController',\n                    'permission-group' => 'PermissionGroupController',\n                    'menu' => 'MenuController',\n                ]);\n\n                $router->get('role/{id}/permissions', 'RoleController@permissions')->name('role.permissions');\n                $router->put('role/{id}/permissions', 'RoleController@assignPermissions')->name('role.assign-permissions');\n                $router->get('guard-name-roles/{guardName}', 'RoleController@guardNameRoles')->name('role.guard-name-roles');\n                $router->get('admin-user/{id}/roles/{guard}', 'AdminUserController@roles')->name('admin-user.roles');\n                $router->put('admin-user/{id}/roles/{guard}', 'AdminUserController@assignRoles')->name('admin-user.assign-roles');\n                $router->get('guard-name-for-permissions/{guardName}', 'PermissionGroupController@guardNameForPermissions')\n                    ->name('permission-group.guard-name-for-permission');\n                $router->get(\"permission-group-all\", \"PermissionGroupController@all\")->name(\"permission-group.all\");\n            });\n        });\n"
  },
  {
    "path": "tests/Feature/AdminUserControllerTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Feature;\n\nuse Moell\\Mojito\\Models\\AdminUser;\nuse DB;\n\nclass AdminUserControllerTest extends FeatureTestCase\n{\n    public function test_paging_data_for_all_admin_users()\n    {\n        factory(AdminUser::class, 79)->create();\n\n        $response = $this->get(route('admin-user.index'));\n\n        $response->assertStatus(200);\n\n        $data =  [\n            'id' => true,\n            'name' => true,\n            'username' => true\n        ];\n\n        $response->assertJson($this->paginateResponseAssertFormat($data, AdminUser::count()));\n    }\n\n    public function test_admin_user_of_the_condition_to_be_filtered()\n    {\n        factory(AdminUser::class, 79)->create();\n\n        $response = $this->get(route('admin-user.index') . '/?name=admin&username=admin');\n\n        $response->assertStatus(200);\n\n        $data =  [\n            'name' => 'admin',\n            'username' => 'admin'\n        ];\n\n        $response->assertJson($this->paginateResponseAssertFormat($data, 1));\n    }\n\n    public function test_store()\n    {\n        $data = [\n            'name' => '111',\n            'username' => 'admintest',\n            'password' => '123446dd',\n            'status' => 1,\n        ];\n\n        $response = $this->post(route('admin-user.store'), $data, $this->jsonHeader());\n        $response->assertStatus(201);\n\n        $adminUser = AdminUser::where('username', $data['username'])->first();\n        $this->assertNotNull($adminUser);\n    }\n\n    public function test_show()\n    {\n        $adminUser = AdminUser::first();\n\n        $response = $this->get(route('admin-user.show', ['admin_user' => $adminUser->id]));\n\n        $response->assertJson([\n            'data' => [\n                'id' => 1,\n                'name' => 'admin',\n                'username' => 'admin'\n            ]\n        ]);\n    }\n\n    public function test_update()\n    {\n        $adminUser = AdminUser::first();\n\n        $data = [\n            'name' => 'admin_test'\n        ];\n\n        $response = $this->patch(route('admin-user.update', ['admin_user' => $adminUser->id]), $data, $this->jsonHeader());\n\n        $response->assertStatus(204);\n\n        $newAdminUser = AdminUser::first();\n        $this->assertEquals($data['name'], $newAdminUser->name);\n        $this->assertEquals($adminUser->password, $newAdminUser->password);\n    }\n\n    public function test_destroy()\n    {\n        $adminUser = AdminUser::first();\n\n        $response = $this->delete(route('admin-user.destroy', ['admin_user' => $adminUser->id]), [], $this->jsonHeader());\n        $response->assertStatus(204);\n\n        $this->assertCount(0, $adminUser->roles);\n        $this->assertCount(0, $adminUser->permissions);\n    }\n\n    public function test_get_a_list_of_roles_based_on_ID()\n    {\n        $adminUser = AdminUser::first();\n\n        $route = route('admin-user.roles', ['id' => $adminUser->id, 'guard' => 'admin']);\n        $response = $this->get($route, $this->jsonHeader());\n\n        $data = [];\n        foreach ($adminUser->roles as $role) {\n            array_push($data, ['name' => $role->name]);\n        }\n\n        $response->assertStatus(200)\n            ->assertJson([\n                'data' => $data\n            ]);\n    }\n\n    public function test_user_assign_roles()\n    {\n        $adminUser = AdminUser::first();\n\n        $route = route('admin-user.roles', ['id' => $adminUser->id, 'guard' => 'admin']);\n        $response = $this->put($route, ['roles' => []], $this->jsonHeader());\n\n        $response->assertStatus(204);\n\n        $this->assertCount(0, $adminUser->roles);\n    }\n}\n"
  },
  {
    "path": "tests/Feature/CaptchaControllerTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Feature;\n\n\nclass CaptchaControllerTest extends FeatureTestCase\n{\n    public function test_generate()\n    {\n        $response = $this->get('/api/captcha', $this->jsonHeader());\n\n        $response->assertJson([\n            'data' => [\n                'key' => true,\n                'expired_at' => true,\n                'image_content' => true\n            ]\n        ]);\n    }\n}\n"
  },
  {
    "path": "tests/Feature/ChangePasswordControllerTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Feature;\n\nuse Illuminate\\Support\\Facades\\Auth;\nuse Illuminate\\Support\\Facades\\Hash;\nuse Moell\\Mojito\\AdminUserFactory;\n\nclass ChangePasswordControllerTest extends FeatureTestCase\n{\n    public function test_change_password()\n    {\n        $newPassword = 'new-mojito-password';\n\n        $user = Auth::user();\n\n        $user->password = bcrypt('mojito-password');\n        $user->save();\n\n        $response = $this->patch(route('user.change-password'), [\n            'old_password' => 'mojito-password',\n            'password' => $newPassword,\n            'password_confirmation' => $newPassword\n        ]);\n\n        $response->assertStatus(204);\n\n        $user = AdminUserFactory::adminUser()->find($user->id);\n\n        $this->assertTrue(Hash::check($newPassword, $user->password), $user->password);\n    }\n}\n"
  },
  {
    "path": "tests/Feature/FeatureTestCase.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Feature;\n\n\nuse Laravel\\Sanctum\\Sanctum;\nuse Moell\\Mojito\\AdminUserFactory;\nuse Moell\\Mojito\\Database\\MojitoTableSeeder;\nuse Moell\\Mojito\\Tests\\TestCase;\n\nclass FeatureTestCase extends TestCase\n{\n    protected function setUp(): void\n    {\n        parent::setUp();\n\n        $this->artisan('db:seed', ['--class' => MojitoTableSeeder::class]);\n\n        $user = AdminUserFactory::adminUser()->first();\n        Sanctum::actingAs(\n            $user,\n            ['*']\n        );\n    }\n\n    /**\n     * @param array $data\n     * @param int $total\n     * @param int $currentPage\n     * @return array\n     */\n    protected function paginateResponseAssertFormat(array $data, $total = 0, $currentPage = 1)\n    {\n        return [\n            'data' => [\n                $data\n            ],\n            'links' => [\n                \"first\" => true,\n                \"last\" => true\n            ],\n            'meta' => [\n                \"current_page\" => $currentPage > 1 ? $currentPage : true,\n                \"from\"  => true,\n                \"last_page\" => true,\n                \"path\"  => true,\n                \"per_page\" => true,\n                \"to\" => true,\n                \"total\" => $total > 0  ? $total : true\n            ]\n        ];\n    }\n\n    /**\n     * @return array\n     */\n    protected function jsonHeader()\n    {\n        return [\n            'Accept' => 'application/json'\n        ];\n    }\n}"
  },
  {
    "path": "tests/Feature/MenuControllerTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Feature;\n\n\nuse Moell\\Mojito\\Models\\Menu;\n\nclass MenuControllerTest extends FeatureTestCase\n{\n    public function test_to_get_a_list_of_menus()\n    {\n        $response = $this->get(route('menu.index'), $this->jsonHeader());\n\n        $response\n            ->assertStatus(200)\n            ->assertJson([\n                'data' => [\n                    [\n                        'id' => 1,\n                        'parent_id' => '0',\n                        'name' => 'Dashboard',\n                        'guard_name' => \"admin\"\n                    ],\n                    [\n                        'id' => 2,\n                        'parent_id' => '0',\n                        'name' => '系统管理',\n                        'guard_name' => \"admin\",\n                        'children' => [\n                            [\n                                'id' => 3,\n                                'parent_id' => '2',\n                                'name' => '管理员',\n                                'guard_name' => \"admin\"\n                            ]\n                        ]\n                    ]\n                ]\n            ]);\n    }\n\n    public function test_menu_after_user_login()\n    {\n        $response = $this->get(route('menu.my'), $this->jsonHeader());\n\n        $response\n            ->assertStatus(200)\n            ->assertJson([\n                'data' => [\n                    [\n                        'id' => 1,\n                        'parent_id' => '0',\n                        'name' => 'Dashboard',\n                        'guard_name' => \"admin\"\n                    ],\n                    [\n                        'id' => 2,\n                        'parent_id' => '0',\n                        'name' => '系统管理',\n                        'guard_name' => \"admin\",\n                        'children' => [\n                            [\n                                'id' => 3,\n                                'parent_id' => '2',\n                                'name' => '管理员',\n                                'guard_name' => \"admin\"\n                            ]\n                        ]\n                    ]\n                ]\n            ]);\n    }\n\n    public function test_create_a_menu()\n    {\n        $data = [\n            'parent_id' => 0,\n            'name' => 'home',\n            'icon' => 'fa fa-home',\n            'uri' => '/',\n            'is_link' => 1,\n            'guard_name' => 'admin',\n            'sequence' => 10\n        ];\n\n        $response = $this->post(route('menu.store'), $data, $this->jsonHeader());\n\n        $response->assertStatus(201);\n\n        $menu = Menu::where('name', $data['name'])->where('guard_name', $data['guard_name'])->first()->toArray();\n        $this->assertArraySubset($data, $menu);\n    }\n\n    public function test_edit_a_menu()\n    {\n        $data = [\n            'parent_id' => 0,\n            'name' => 'home',\n            'icon' => 'fa fa-home',\n            'uri' => '/',\n            'is_link' => 1,\n            'guard_name' => 'admin',\n            'sequence' => 0\n        ];\n\n        $menu = Menu::query()->where('parent_id', '>', 0)->first();\n\n        $response = $this->patch(route('menu.update', ['menu' => $menu->id]), $data, $this->jsonHeader());\n        $response->assertStatus(204);\n\n        $this->assertArraySubset($data, Menu::query()->find($menu->id)->toArray());\n    }\n\n    public function test_menu_id_for_details()\n    {\n        $menu = Menu::query()->first();\n\n        $response = $this->get(route('menu.show', ['menu' => $menu->id]), $this->jsonHeader());\n        $response\n            ->assertStatus(200)\n            ->assertJson([\n                'data' => [\n                    'name' => $menu->name,\n                    'guard_name' => $menu->guard_name\n                ]\n            ]);\n    }\n\n    public function test_menu_id_for_destroy()\n    {\n        $menu = Menu::query()->first();\n\n        $childMenu = Menu::create([\n            'name' => 'test',\n            'guard_name' => 'test',\n            'parent_id' => $menu->id\n        ]);\n\n        $response = $this->delete(route('menu.destroy', ['menu' => $menu->id]), $this->jsonHeader());\n        $response->assertStatus(422);\n\n        $childResponse = $this->delete(route('menu.destroy', ['menu' => $childMenu->id]), $this->jsonHeader());\n        $childResponse->assertStatus(204);\n    }\n\n}\n"
  },
  {
    "path": "tests/Feature/PermissionControllerTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Feature;\n\n\nuse Spatie\\Permission\\Models\\Permission;\n\nclass PermissionControllerTest extends FeatureTestCase\n{\n    public function test_get_permission_list()\n    {\n        $response = $this->get(route('permission.index') . '?name=admin-user.index', $this->jsonHeader());\n\n        $data = [\n            'name' => 'admin-user.index'\n        ];\n\n        $response\n            ->assertStatus(200)\n            ->assertJson($this->paginateResponseAssertFormat($data, 1));\n    }\n\n    public function test_create_a_permission()\n    {\n        $data = [\n            'pg_id' => 1,\n            'name' => 'permission.test',\n            'guard_name' => 'admin',\n            'display_name' => 'test',\n            'icon' => 'fa fa-edit',\n            'sequence' => '1',\n            'description' => 'description'\n        ];\n\n        $response = $this->post(route('permission.store'), $data, $this->jsonHeader());\n\n        $response->assertStatus(201);\n\n        $permission = Permission::query()\n            ->where('name', $data['name'])\n            ->where('guard_name', $data['guard_name'])\n            ->first();\n        $this->assertNotNull($permission);\n    }\n\n    public function test_permission_id_for_details()\n    {\n        $permission = Permission::query()->first(['id', 'name', 'guard_name', 'display_name', 'icon', 'sequence', 'description']);\n\n        $response = $this->get(route('permission.show', ['permission' => $permission->id]), $this->jsonHeader());\n        $response\n            ->assertStatus(200)\n            ->assertJson([\n                'data' => $permission->toArray()\n            ]);\n\n    }\n\n    public function test_update_a_permission()\n    {\n        $data = [\n            'pg_id' => 1,\n            'name' => 'permission.test',\n            'guard_name' => 'admin',\n            'display_name' => 'test',\n            'icon' => 'fa fa-edit',\n            'sequence' => '1',\n            'description' => 'description'\n        ];\n\n        $permission = Permission::query()->first();\n\n        $response = $this->patch(\n            route('permission.update', ['permission' => $permission->id]), $data, $this->jsonHeader()\n        );\n\n        $response->assertStatus(204);\n\n        $this->assertArraySubset($data, Permission::query()->find($permission->id)->toArray());\n    }\n\n    public function test_delete_the_specified_ID_permission()\n    {\n        $permission = Permission::query()->first();\n\n        $response = $this->delete(\n            route('permission.destroy', ['permission' => $permission->id]), $this->jsonHeader()\n        );\n\n        $response->assertStatus(204);\n        $this->assertNull(Permission::query()->find($permission->id));\n    }\n\n    public function test_user_all_permission()\n    {\n        $response = $this->get(route('permission.all-user-permission'), $this->jsonHeader());\n\n        $response->assertStatus(200);\n    }\n}"
  },
  {
    "path": "tests/Feature/PermissionGroupControllerTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Feature;\n\n\nuse Moell\\Mojito\\Models\\PermissionGroup;\n\nclass permissionGroupControllerTest extends FeatureTestCase\n{\n    public function test_get_permission_group_list()\n    {\n        $response = $this->get(route('permission-group.index'), $this->jsonHeader());\n\n        $response\n            ->assertStatus(200)\n            ->assertJson($this->paginateResponseAssertFormat([\n                'name' => true\n            ]));\n    }\n\n    public function test_get_permission_group_all()\n    {\n        $response = $this->get(route('permission-group.all'), $this->jsonHeader());\n\n        $response\n            ->assertStatus(200)\n            ->assertJson([\n                'data' => [\n                    [\n                        'id' => true,\n                        'name' => true\n                    ]\n                ]\n            ]);\n    }\n\n    public function test_get_guard_name_group_permissions()\n    {\n        $response = $this->get(route('permission-group.guard-name-for-permission', ['guardName' => 'admin']), $this->jsonHeader());\n\n        $response\n            ->assertStatus(200)\n            ->assertJson([\n                'data' => [\n                    [\n                        'id' => true,\n                        'name' => true,\n                        'permission' => true\n                    ]\n                ]\n            ]);\n    }\n\n    public function test_create_a_permission_group()\n    {\n        $data = ['name' => 'test permission group'];\n\n        $response = $this->post(route('permission-group.store'), $data, $this->jsonHeader());\n\n        $response->assertStatus(201);\n\n        $this->assertNotNull(PermissionGroup::query()->where('name', $data['name'])->first());\n    }\n\n    public function test_permission_group_id_for_details()\n    {\n        $permissionGroup = PermissionGroup::query()->first();\n\n        $response = $this->get(\n            route('permission-group.show', ['permission_group' => $permissionGroup->id]), $this->jsonHeader()\n        );\n\n        $response\n            ->assertStatus(200)\n            ->assertJson(['data' => [\n                'name' => $permissionGroup->name\n            ]]);\n    }\n\n    public function test_update_a_permission_group()\n    {\n        $data = ['name' => 'test permission group'];\n\n        $permissionGroup = PermissionGroup::query()->first();\n\n        $response = $this->patch(\n            route('permission-group.update', ['permission_group' => $permissionGroup->id]), $data, $this->jsonHeader()\n        );\n\n        $response->assertStatus(204);\n\n        $new = PermissionGroup::query()->find($permissionGroup->id);\n\n        $this->assertEquals($new->name, $data['name']);\n    }\n\n    public function test_delete_the_specified_ID_permission_group()\n    {\n        $permissionGroup = PermissionGroup::query()->first();\n\n        $response = $this->delete(route('permission-group.destroy', ['permission_group' => $permissionGroup->id]));\n\n        $response->assertStatus(422);\n\n        $new = PermissionGroup::create([\n            'name' => 'test'\n        ]);\n\n        $newResponse = $this->delete(route('permission-group.destroy', ['permission_group' => $new->id]));\n\n        $newResponse->assertStatus(204);\n        $this->assertNull(PermissionGroup::query()->find($new->id));\n    }\n}"
  },
  {
    "path": "tests/Feature/RoleControllerTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Feature;\n\n\nuse Spatie\\Permission\\Models\\Role;\n\nclass RoleControllerTest extends FeatureTestCase\n{\n    public function test_to_get_a_list_of_roles()\n    {\n        $response = $this->get(route('role.index') . '?name=admin', $this->jsonHeader());\n\n        $response\n            ->assertStatus(200)\n            ->assertJson($this->paginateResponseAssertFormat([\n                'name' => 'admin'\n            ]));\n    }\n\n    public function test_create_a_role()\n    {\n        $data = [\n            'name' => 'test',\n            'guard_name' => 'test',\n            'description' => 'test description'\n        ];\n\n        $response = $this->post(route('role.store'), $data, $this->jsonHeader());\n\n        $response->assertStatus(201);\n    }\n\n    public function test_edit_a_role()\n    {\n        $role = Role::query()->first();\n\n        $data =  [\n            'name' =>  'test',\n            'guard_name' => 'test'\n        ];\n\n        $response = $this->patch(route('role.update', ['role' => $role->id]), $data, $this->jsonHeader());\n\n        $response->assertStatus(204);\n\n        $role = Role::query()->first();\n        $this->assertEquals($data['name'], $role->name);\n        $this->assertEquals($data['guard_name'], $role->guard_name);\n    }\n\n    public function test_role_assign_permission()\n    {\n        $role = Role::query()->first();\n\n        $response = $this->put(route('role.assign-permissions', ['id' => $role->id]), ['permissions' => []], $this->jsonHeader());\n\n        $response->assertStatus(204);\n\n        $this->assertCount(0, $role->permissions);\n    }\n\n    public function test_guard_name_for_roels()\n    {\n        $response = $this->get(route('role.guard-name-roles', ['guardName' => 'admin']), $this->jsonHeader());\n\n        $response->assertStatus(200)->assertJson([\n            'data' => [\n                ['guard_name' => 'admin']\n            ]\n        ]);\n    }\n\n    public function test_get_role_permissions()\n    {\n        $role = Role::query()->first();\n\n        $response = $this->get(route('role.permissions', ['id' => $role->id]), $this->jsonHeader());\n\n        $count = $role->permissions()->orderBy('id')->count();\n\n        $response->assertStatus(200);\n\n        $this->assertCount($count, json_decode($response->getContent())->data);\n    }\n\n    public function test_role_id_for_details()\n    {\n        $role = Role::query()->first();\n\n        $response = $this->get(route('role.show', ['role' => $role->id]), $this->jsonHeader());\n\n        $response\n            ->assertStatus(200)\n            ->assertJson([\n                'data' => [\n                    'name' => $role->name,\n                    'guard_name' => $role->guard_name\n                ]\n            ]);\n    }\n\n    public function test_role_id_for_destroy()\n    {\n        $role = Role::create(['name' => 'test', 'guard_name' => 'test']);\n\n        $response = $this->delete(route('role.destroy', ['role' => $role->id]), $this->jsonHeader());\n\n        $response->assertStatus(204);\n\n        $this->assertNull(Role::query()->find($role->id));\n    }\n\n}\n"
  },
  {
    "path": "tests/Fixtures/Http/Kernel.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Fixtures\\Http;\n\nuse Laravel\\Sanctum\\Http\\Middleware\\EnsureFrontendRequestsAreStateful;\nuse Orchestra\\Testbench\\Foundation\\Http\\Kernel as HttpKernel;\n\nclass Kernel extends HttpKernel\n{\n    protected $routeMiddleware = [\n        'auth' => \\Illuminate\\Auth\\Middleware\\Authenticate::class,\n        'auth.basic' => \\Illuminate\\Auth\\Middleware\\AuthenticateWithBasicAuth::class,\n        'bindings' => \\Illuminate\\Routing\\Middleware\\SubstituteBindings::class,\n        'cache.headers' => \\Illuminate\\Http\\Middleware\\SetCacheHeaders::class,\n        'can' => \\Illuminate\\Auth\\Middleware\\Authorize::class,\n        'guest' => \\Orchestra\\Testbench\\Http\\Middleware\\RedirectIfAuthenticated::class,\n        'mojito.permission' => \\Moell\\Mojito\\Http\\Middleware\\Authenticate::class,\n        'signed' => \\Illuminate\\Routing\\Middleware\\ValidateSignature::class,\n        'throttle' => \\Illuminate\\Routing\\Middleware\\ThrottleRequests::class,\n    ];\n\n\n    protected $middlewareGroups = [\n        'api' => [\n            'throttle:60,1',\n            \\Illuminate\\Routing\\Middleware\\SubstituteBindings::class,\n            EnsureFrontendRequestsAreStateful::class,\n        ],\n    ];\n}"
  },
  {
    "path": "tests/Fixtures/database/factories/AdminUserFactory.php",
    "content": "<?php\n\nuse Faker\\Generator as Faker;\n\n/*\n|--------------------------------------------------------------------------\n| Model Factories\n|--------------------------------------------------------------------------\n|\n| This directory should contain each of the model factory definitions for\n| your application. Factories provide a convenient way to generate new\n| model instances for testing / seeding your application's database.\n|\n*/\n\n$factory->define(\\Moell\\Mojito\\Models\\AdminUser::class, function (Faker $faker) {\n    return [\n        'name' => $faker->name,\n        'username' => $faker->unique()->userName,\n        'status' => 1,\n        'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret\n    ];\n});"
  },
  {
    "path": "tests/Fixtures/database/migrations/0000_00_00_000001_create_permission_test_tables.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nclass CreatePermissionTestTables extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        $tableNames = config('permission.table_names');\n\n        Schema::create($tableNames['permissions'], function (Blueprint $table) {\n            $table->increments('id');\n            $table->string('name');\n            $table->string('guard_name');\n            $table->timestamps();\n        });\n\n        Schema::create($tableNames['roles'], function (Blueprint $table) {\n            $table->increments('id');\n            $table->string('name');\n            $table->string('guard_name');\n            $table->timestamps();\n        });\n\n        Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames) {\n            $table->unsignedInteger('permission_id');\n            $table->morphs('model');\n\n            $table->foreign('permission_id')\n                ->references('id')\n                ->on($tableNames['permissions'])\n                ->onDelete('cascade');\n\n            $table->primary(['permission_id', 'model_id', 'model_type'], 'model_has_permissions_permission_model_type_primary');\n        });\n\n        Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames) {\n            $table->unsignedInteger('role_id');\n            $table->morphs('model');\n\n            $table->foreign('role_id')\n                ->references('id')\n                ->on($tableNames['roles'])\n                ->onDelete('cascade');\n\n            $table->primary(['role_id', 'model_id', 'model_type']);\n        });\n\n        Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) {\n            $table->unsignedInteger('permission_id');\n            $table->unsignedInteger('role_id');\n\n            $table->foreign('permission_id')\n                ->references('id')\n                ->on($tableNames['permissions'])\n                ->onDelete('cascade');\n\n            $table->foreign('role_id')\n                ->references('id')\n                ->on($tableNames['roles'])\n                ->onDelete('cascade');\n\n            $table->primary(['permission_id', 'role_id']);\n\n            app('cache')->forget('spatie.permission.cache');\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        $tableNames = config('permission.table_names');\n\n        Schema::drop($tableNames['role_has_permissions']);\n        Schema::drop($tableNames['model_has_roles']);\n        Schema::drop($tableNames['model_has_permissions']);\n        Schema::drop($tableNames['roles']);\n        Schema::drop($tableNames['permissions']);\n    }\n}\n"
  },
  {
    "path": "tests/Fixtures/database/migrations/0000_00_00_000002_add_custom_field_permission_test_tables.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nclass AddCustomFieldPermissionTestTables extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        $tableNames = config('permission.table_names');\n\n        Schema::table($tableNames['permissions'], function (Blueprint $table) {\n            $table->integer('pg_id')->default(0);\n            $table->string('display_name', 50)->nullable();\n            $table->string('icon', 30)->nullable();\n            $table->smallInteger('sequence')->default(0);\n            $table->string('created_name', 50)->nullable();\n            $table->string('updated_name', 50)->nullable();\n            $table->string('description')->nullable();\n        });\n\n        Schema::table($tableNames['roles'], function (Blueprint $table) {\n            $table->string('description')->nullable();\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        $tableNames = config('permission.table_names');\n\n        Schema::table($tableNames['permissions'], function (Blueprint $table) {\n            $table->dropColumn([\n                'pg_id',\n                'display_name',\n                'icon',\n                'sequence',\n                'created_name',\n                'updated_name',\n                'description'\n            ]);\n        });\n\n        Schema::table($tableNames['roles'], function (Blueprint $table) {\n            $table->dropColumn('description');\n        });\n    }\n}\n"
  },
  {
    "path": "tests/Fixtures/database/migrations/0000_00_00_000003_create_admin_test_table.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nclass CreateAdminTestTable extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::create('admin_users', function (Blueprint $table) {\n            $table->increments('id');\n            $table->string('name');\n            $table->string('username')->unique();\n            $table->string('password');\n            $table->boolean(\"status\");\n            $table->rememberToken();\n            $table->timestamps();\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        Schema::dropIfExists('admin_users');\n    }\n}\n"
  },
  {
    "path": "tests/Fixtures/database/migrations/0000_00_00_000004_create_permission_group_test_table.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nclass CreatePermissionGroupTestTable  extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::create('permission_groups', function (Blueprint $table) {\n            $table->increments('id');\n            $table->string('name');\n            $table->timestamps();\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        Schema::dropIfExists('permission_groups');\n    }\n}"
  },
  {
    "path": "tests/Fixtures/database/migrations/0000_00_00_000005_create_menu_test_table.php",
    "content": "<?php\n\nuse Illuminate\\Support\\Facades\\Schema;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nclass CreateMenuTestTable  extends Migration\n{\n    /**\n     * Run the migrations.\n     *\n     * @return void\n     */\n    public function up()\n    {\n        Schema::create('menus', function (Blueprint $table) {\n            $table->increments('id');\n            $table->integer('parent_id')->default(0);\n            $table->string('icon', 50)->nullable();\n            $table->string('uri')->nullable();\n            $table->tinyInteger('is_link')->nullable()->comment('0-no;1-yes');\n            $table->string('permission_name', 50)->nullable();\n            $table->string('name');\n            $table->string('guard_name', 30);\n            $table->smallInteger('sequence')->default(0);\n            $table->timestamps();\n        });\n    }\n\n    /**\n     * Reverse the migrations.\n     *\n     * @return void\n     */\n    public function down()\n    {\n        Schema::dropIfExists('menus');\n    }\n}"
  },
  {
    "path": "tests/TestCase.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests;\n\nuse DMS\\PHPUnitExtensions\\ArraySubset\\ArraySubsetAsserts;\nuse Laravel\\Passport\\PassportServiceProvider;\nuse Laravel\\Sanctum\\SanctumServiceProvider;\nuse Moell\\Mojito\\Models\\AdminUser;\nuse Moell\\Mojito\\Providers\\MojitoServiceProvider;\nuse Moell\\Mojito\\Tests\\Fixtures\\Http\\Kernel;\nuse Orchestra\\Testbench\\TestCase as BaseTestCase;\nuse SMartins\\PassportMultiauth\\Providers\\MultiauthServiceProvider;\nuse Spatie\\Permission\\Models\\Permission;\nuse Spatie\\Permission\\Models\\Role;\nuse Spatie\\Permission\\PermissionServiceProvider;\n\nabstract class TestCase extends BaseTestCase\n{\n    use ArraySubsetAsserts;\n\n    protected function setUp(): void\n    {\n        parent::setUp();\n\n        $this->artisan('migrate', ['--database' => 'mojito']);\n\n        $this->loadMigrationsFrom(__DIR__ . '/Fixtures/database/migrations');\n\n        $this->withFactories(__DIR__ . '/Fixtures/database/factories');\n    }\n\n    protected function getEnvironmentSetUp($app)\n    {\n        $app['config']->set('database.default', 'mojito');\n        $app['config']->set('database.connections.mojito', [\n            'driver'   => 'sqlite',\n            'database' => ':memory:',\n            'prefix'   => '',\n        ]);\n\n        $this->setMojitoConfigs();\n\n        $this->setPermissionConfigs();\n    }\n\n    protected function getPackageProviders($app)\n    {\n        return [\n            PermissionServiceProvider::class,\n            MojitoServiceProvider::class,\n            SanctumServiceProvider::class\n        ];\n    }\n\n    protected function resolveApplicationHttpKernel($app)\n    {\n        $app->singleton('Illuminate\\Contracts\\Http\\Kernel', Kernel::class);\n    }\n\n    protected function setMojitoConfigs()\n    {\n        config(['mojito' => include __DIR__ . '/../config/mojito.php']);\n    }\n\n    protected function setPermissionConfigs()\n    {\n        config(['permission' => [\n            'models' => [\n                'permission' => Permission::class,\n                'role' => Role::class,\n            ],\n            'table_names' => [\n                'roles' => 'roles',\n                'permissions' => 'permissions',\n                'model_has_permissions' => 'model_has_permissions',\n                'model_has_roles' => 'model_has_roles',\n                'role_has_permissions' => 'role_has_permissions',\n            ],\n            'cache_expiration_time' => 60 * 24,\n            'display_permission_in_exception' => false,\n        ]]);\n    }\n}\n"
  },
  {
    "path": "tests/Unit/AdminUserFactoryTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Unit;\n\n\nuse Moell\\Mojito\\AdminUserFactory;\nuse Moell\\Mojito\\Models\\AdminUser;\nuse Moell\\Mojito\\Tests\\TestCase;\n\nclass AdminUserFactoryTest extends TestCase\n{\n    protected function setUp(): void\n    {\n        $this->setUpTheTestEnvironment();\n    }\n\n    public function test_if_it_is_admin_user()\n    {\n        $model = AdminUserFactory::adminUser();\n\n        $this->assertInstanceOf(AdminUser::class, $model);\n    }\n}"
  },
  {
    "path": "tests/Unit/Requests/AdminUserCreateOrUpdateRequestTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Unit\\Requests;\n\n\nuse Moell\\Mojito\\Http\\Requests\\AdminUser\\CreateOrUpdateRequest;\nuse Moell\\Mojito\\Tests\\TestCase;\nuse Validator;\n\n\nclass AdminUserCreateOrUpdateRequestTest extends TestCase\n{\n    public function test_create_form_request()\n    {\n        $request = new CreateOrUpdateRequest();\n        $request->setMethod('POST');\n\n        $attributes = [\n            'name' => 'test',\n            'username' => 'test111',\n            'password' => '12345544'\n        ];\n\n        $validator = Validator::make($attributes, $request->rules());\n\n        $this->assertEquals(false, $validator->fails());\n    }\n\n    public function test_update_form_request()\n    {\n        $request = new CreateOrUpdateRequest();\n        $request->setMethod('PATCH');\n\n        $attributes = [\n            'name' => 'test',\n            'password' => '123455'\n        ];\n\n        $validator = Validator::make($attributes, $request->rules());\n\n        $this->assertEquals(true, $validator->fails());\n        $this->assertArrayHasKey('password', $validator->errors()->toArray());\n    }\n}"
  },
  {
    "path": "tests/Unit/Requests/ChangePasswordRequestTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Unit\\Requests;\n\n\nuse Moell\\Mojito\\Http\\Requests\\ChangePasswordRequest;\nuse Moell\\Mojito\\Tests\\TestCase;\nuse Validator;\n\n\nclass ChangePasswordRequestTest extends TestCase\n{\n    public function test_change_password_request()\n    {\n        $request = new ChangePasswordRequest();\n        $request->setMethod('PATCH');\n\n        $attributes = [\n            'old_password' => 'testtest',\n            'password' => 'test1esss',\n            'password_confirmation' => 'test1esss'\n        ];\n\n        $validator = Validator::make($attributes, $request->rules());\n\n        $this->assertEquals(false, $validator->fails());\n    }\n}"
  },
  {
    "path": "tests/Unit/Requests/MenuCreateOrUpdateRequestTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Unit\\Requests;\n\n\nuse Moell\\Mojito\\Http\\Requests\\Menu\\CreateOrUpdateRequest;\nuse Moell\\Mojito\\Tests\\TestCase;\nuse Validator;\n\nclass MenuCreateOrUpdateRequestTest extends TestCase\n{\n    public function test_create_or_update_form_request()\n    {\n        $request = new CreateOrUpdateRequest();\n\n        $attributes = [\n            'parent_id' => 0,\n            'name' => 'home',\n            'icon' => 'fa fa-home',\n            'uri' => '/',\n            'is_link' => 1,\n            'guard_name' => 'admin'\n        ];\n\n        $validator = Validator::make($attributes, $request->rules());\n\n        $this->assertEquals(false, $validator->fails());\n\n        $validator = Validator::make([], $request->rules());\n\n        $errors = $validator->errors()->toArray();\n        $keys = ['parent_id', 'name', 'guard_name', 'uri'];\n        foreach ($keys as $key) {\n            $this->assertArrayHasKey($key, $errors);\n        }\n    }\n}"
  },
  {
    "path": "tests/Unit/Requests/PermissionCreateOrUpdateRequestTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Unit\\Requests;\n\n\nuse Moell\\Mojito\\Http\\Requests\\Permission\\CreateOrUpdateRequest;\nuse Moell\\Mojito\\Tests\\TestCase;\nuse Validator;\n\nclass PermissionCreateOrUpdateRequestTest extends TestCase\n{\n    public function test_create_or_update_form_request()\n    {\n        $request = new CreateOrUpdateRequest();\n\n        $attributes = [\n            'pg_id' => 1,\n            'name' => 'permission.test',\n            'guard_name' => 'admin',\n            'display_name' => 'test',\n            'icon' => 'fa fa-edit',\n            'sequence' => '1',\n            'description' => 'description'\n        ];\n\n        $validator = Validator::make($attributes, $request->rules());\n\n        $this->assertEquals(false, $validator->fails());\n\n\n        $validator = Validator::make([], $request->rules());\n\n        $this->assertEquals(true, $validator->fails());\n\n        $keys = [\n            'name', 'guard_name', 'display_name', 'pg_id'\n        ];\n        foreach ($keys as $key) {\n            $this->assertArrayHasKey($key, $validator->errors()->toArray());\n        }\n    }\n}"
  },
  {
    "path": "tests/Unit/Requests/PermissionGroupCreateOrUpdateRequestTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Unit\\Requests;\n\n\nuse Moell\\Mojito\\Http\\Requests\\PermissionGroup\\CreateOrUpdateRequest;\nuse Moell\\Mojito\\Tests\\TestCase;\nuse Validator;\n\nclass PermissionGroupCreateOrUpdateRequestTest extends TestCase\n{\n    public function test_create_or_update_form_request()\n    {\n        $request = new CreateOrUpdateRequest();\n\n        $attributes = [\n            'name' => 'name'\n        ];\n\n        $validator = Validator::make($attributes, $request->rules());\n\n        $this->assertEquals(false, $validator->fails());\n\n        $validator = Validator::make([], $request->rules());\n\n        $this->assertEquals(true, $validator->fails());\n    }\n}"
  },
  {
    "path": "tests/Unit/Requests/RoleCreateOrUpdateRequestTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Unit\\Requests;\n\n\nuse Moell\\Mojito\\Http\\Requests\\Role\\CreateOrUpdateRequest;\nuse Moell\\Mojito\\Tests\\TestCase;\nuse Validator;\n\nclass RoleCreateOrUpdateRequestTest extends TestCase\n{\n    public function test_create_or_update_form_request()\n    {\n        $request = new CreateOrUpdateRequest();\n\n        $attributes = [\n            'name' => 'name'\n        ];\n\n        $validator = Validator::make($attributes, $request->rules());\n\n        $this->assertEquals(true, $validator->fails());\n\n        $failAttributes = [\n            'name' => 'name',\n            'guard_name' => 'guard_name'\n        ];\n\n        $validator = Validator::make($failAttributes, $request->rules());\n\n        $this->assertEquals(false, $validator->fails());\n    }\n}"
  },
  {
    "path": "tests/Unit/ResponseTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Unit;\n\n\nuse Moell\\Mojito\\Http\\MojitoResponse;\nuse Moell\\Mojito\\Tests\\TestCase;\n\nclass ResponseTest extends TestCase\n{\n    use MojitoResponse;\n\n    protected function setUp(): void\n    {\n        $this->setUpTheTestEnvironment();\n    }\n\n    public function test_http_ok()\n    {\n        $data = ['name' => 'moell'];\n\n        $response = $this->success($data);\n\n        $this->assertEquals($response->getStatusCode(), 200);\n        $this->assertJsonStringEqualsJsonString(json_encode($data), $response->getContent());\n    }\n\n    public function test_http_created()\n    {\n        $response = $this->created();\n\n        $this->assertEquals($response->getStatusCode(), 201);\n    }\n\n    public function test_http_accepted()\n    {\n        $response = $this->accepted();\n\n        $this->assertEquals($response->getStatusCode(), 202);\n    }\n\n    public function test_http_not_content()\n    {\n        $response = $this->noContent();\n\n        $this->assertEquals($response->getStatusCode(), 204);\n    }\n\n    public function test_http_bad_request()\n    {\n        $response = $this->badRequest('error');\n\n        $this->assertEquals($response->getStatusCode(), 400);\n        $this->assertJsonStringEqualsJsonString(json_encode(['message' => 'error']), $response->getContent());\n    }\n\n    public function test_http_unauthorized()\n    {\n        $response = $this->unauthorized('unauthorized');\n\n        $this->assertEquals($response->getStatusCode(), 401);\n        $this->assertJsonStringEqualsJsonString(json_encode(['message' => 'unauthorized']), $response->getContent());\n    }\n\n    public function test_http_forbidden()\n    {\n        $response = $this->forbidden('forbidden');\n\n        $this->assertEquals($response->getStatusCode(), 403);\n        $this->assertJsonStringEqualsJsonString(json_encode(['message' => 'forbidden']), $response->getContent());\n    }\n\n    public function test_http_unprocesable_etity()\n    {\n        $response = $this->unprocesableEtity();\n\n        $this->assertEquals($response->getStatusCode(), 422);\n    }\n}"
  },
  {
    "path": "tests/Unit/ServiceProviderTest.php",
    "content": "<?php\n\nnamespace Moell\\Mojito\\Tests\\Unit;\n\nuse Laravel\\Passport\\PassportServiceProvider;\nuse Laravel\\Sanctum\\SanctumServiceProvider;\nuse Moell\\Mojito\\Providers\\MojitoServiceProvider;\nuse Moell\\Mojito\\Tests\\TestCase;\nuse SMartins\\PassportMultiauth\\Providers\\MultiauthServiceProvider;\nuse Spatie\\Permission\\PermissionServiceProvider;\n\nclass ServiceProviderTest extends TestCase\n{\n    protected function setUp(): void\n    {\n        $this->setUpTheTestEnvironment();\n    }\n\n    public function test_if_the_service_provider_was_loaded()\n    {\n        $providers = $this->app->getLoadedProviders();\n\n        $this->assertArrayHasKey(PermissionServiceProvider::class, $providers);\n\n        $this->assertArrayHasKey(MojitoServiceProvider::class, $providers);\n\n        $this->assertArrayHasKey(SanctumServiceProvider::class, $providers);\n    }\n}\n"
  }
]