ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
1.创建迁移文件。 ``` php artisan module:make-migration create_auths_table AuthAdmin ``` ![](https://img.kancloud.cn/67/a1/67a1ab1c72b7c775e4683e7e5d026494_573x347.png) ![](https://img.kancloud.cn/09/6b/096b74cb309d0b2a64d459ace8993acd_1039x281.png) 2.创建后台管理员相关表。 ``` <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateAuthsTable extends Migration { public function up() { Schema::create('auth_admins', function (Blueprint $table) { //$table->comment = '管理员表'; $table->increments('id')->comment('管理员ID'); $table->string('name',100)->default('')->comment('名称'); $table->string('phone',100)->default('')->comment('电话'); $table->string('username',50)->unique()->default('')->comment('账号'); $table->string('password')->default('')->comment('密码'); $table->integer('group_id')->nullable()->comment('权限组ID'); $table->tinyInteger('status')->default(1)->comment('状态:0=禁用,1=启用'); $table->integer('province_id')->nullable()->comment('省ID'); $table->string('province_name',30)->default('')->comment('省名称'); $table->integer('city_id')->nullable()->comment('市'); $table->string('city_name',30)->default('')->comment('市名称'); $table->integer('county_id')->nullable()->comment('区/县ID'); $table->string('county_name',30)->default('')->comment('区/县名称'); $table->string('address')->default('')->comment('详细地址'); $table->string('lat',30)->default('')->comment('精度'); $table->string('lng',30)->default('')->comment('纬度'); $table->decimal('money',8,2)->default('0.00')->comment('剩余营业额'); $table->decimal('max_money',8,2)->default('0.00')->comment('总余营业额'); $table->integer('sort')->default(1)->comment('排序'); $table->string('api_token', 200)->unique()->nullable()->comment('api_token'); $table->timestamp('overtime_token')->nullable()->comment('token过期时间'); $table->timestamp('created_at')->nullable()->comment('创建时间'); $table->timestamp('updated_at')->nullable()->comment('更新时间'); }); Schema::create('auth_groups', function (Blueprint $table) { //$table->comment = '权限组表'; $table->increments('id')->comment('权限组ID'); $table->string('title',100)->unique()->default('')->comment('权限名称'); $table->tinyInteger('status')->default(1)->comment('状态:0=禁用,1=启用'); $table->longtext('rules')->nullable()->comment('权限规则多个用|隔开'); $table->timestamp('created_at')->nullable()->comment('创建时间'); $table->timestamp('updated_at')->nullable()->comment('更新时间'); }); Schema::create('auth_rules', function (Blueprint $table) { //$table->comment = '权限表'; $table->increments('id')->comment('权限列表ID'); $table->string('href',100)->unique()->default('')->comment('路由地址'); $table->string('title',100)->default('')->comment('中文名称'); $table->tinyInteger('status')->default(1)->comment('侧边栏显示状态:0=隐藏,1=显示'); $table->tinyInteger('auth_open')->default(1)->comment('是否验证权限:0=否,1=是'); $table->string('icon',50)->nullable()->comment('图标'); $table->integer('pid')->default(0)->comment('父级ID'); $table->integer('sort')->default(1)->comment('排序'); $table->timestamp('created_at')->nullable()->comment('创建时间'); $table->timestamp('updated_at')->nullable()->comment('更新时间'); }); } public function down() { Schema::dropIfExists('auth_admins'); Schema::dropIfExists('auth_groups'); Schema::dropIfExists('auth_rules'); } } ``` 3.修改config/database.php ![](https://img.kancloud.cn/26/13/2613f78ca0bee839c889452bcc80f74f_1140x547.png) 4.修改.env文件。 ![](https://img.kancloud.cn/a7/4a/a74a3974922cb5022e4dcccc2c3f6b99_1185x451.png) 5.创建mysql数据库。 ![](https://img.kancloud.cn/bb/1f/bb1f7e957ea34366df4f5d695da3f5a0_443x395.png) 6.执行迁移文件。 ``` php artisan module:migrate AuthAdmin ``` ![](https://img.kancloud.cn/d1/d3/d1d33a3966f265fb43a755b10df68cca_1028x333.png) 7.我们发现了个问题表中的字段有注释,但是表却没有注释。 ![](https://img.kancloud.cn/66/b4/66b41193a7e0636b03abb2934be4faa2_1171x435.png) 8.用composer拉取 zedisdog/laravel-schema-extend 扩展。 ~~~ composer require zedisdog/laravel-schema-extend ~~~ 9.申明依赖 (修改config->app.php->aliases) ~~~ 'aliases' => [ ... // 'Schema' => Illuminate\Support\Facades\Schema::class, 'Schema' => Jialeo\LaravelSchemaExtend\Schema::class, ], ~~~ 10.使用(默认创建的migration文件对应的“Schema”还是引用的laravel自带的,需要修改为该组件包的引用) ~~~ //use Illuminate\Support\Facades\Schema; use Jialeo\LaravelSchemaExtend\Schema; Schema::create('users', function (Blueprint $table) { $table->comment = '用户表'; }); ~~~ 11.完成。 ![](https://img.kancloud.cn/c2/e5/c2e558fc07f67fb4594381381df2d2cf_1022x552.png) 视频链接 ```[youku] XNDU0MDIxMTQ2NA ```