# laravel-migrate **Repository Path**: xudong7930/laravel-migrate ## Basic Information - **Project Name**: laravel-migrate - **Description**: laravel5.6的版本,去掉了不用的代码,尽可能的精简,只需要migrate的功能,专门用来设计表的。 在一个文件里设计好所有的表,然后一个命令建表。 在一个文件里把假数据弄好,然后一个命令填充假数据。 真的非常的棒,非常的方便! - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-12-10 - **Last Updated**: 2024-06-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: 数据库设计 ## README # laravel-migrate laravel5.6的版本,去掉了不用的代码,尽可能的精简,只需要migrate的功能,专门用来设计表的。 在一个文件里设计好所有的表,然后一个命令建表。 在一个文件里把假数据弄好,然后一个命令填充假数据。 真的非常的棒,非常的方便! ## 模板 ```php $this->create('users', '用户表', function(Blueprint $table){ $table->increments('id'); ################################################ $table->integer('user_id')->comment('会员ID'); $table->smallInteger('cate_id')->comment('分类ID'); $table->string('title')->comment('标题'); $table->longText('content')->comment('内容'); ################################################ $table->timestamps(); $table->engine = 'InnoDB'; }); ``` ## 表设计用法 ```php ###################################################### // 字符串,默认191长度 $table->string('email')->nullable(false)->default()->comment('email'); ###################################################### // 时间日期, 2020-10-23 10:23:10 $table->dateTime('valid_at')->nullable(true)->comment('有效日期');; // 时间戳,1639177553 $table->timestamp('added_at')->nullable(true)->comment('added_at'); // 时间戳: created_at, updated_at, $table->timestamps(); ###################################################### // 浮点数,默认8,2 $table->decimal('amount', 10, 2)->default(0.00)->comment('余额'); // 整形数 $table->integer('votes')->unsigned()->default(0)->comment('投票数'); // 小整数 $table->tinyInteger('pay_status')->unsigned()->default(0)->comment('支付状态: 0-未支付 1-已支付'); // 加入audit_id, audit_type字段,不能跟注解 $table->morphs('audit'); // 布尔值,tinyint类型 $table->boolean('confirmed')->nullable(false)->default(0)->comment('是否确认: 1-确认 0-未确认'); ###################################################### // json: 5.7支持,5.6使用longText代替 $table->json('options')->comment('options'); // 文本 $table->text('description')->nullable(true)->comment('desc text'); $table->longText('long_description')->nullable(true)->comment('long text'); ###################################################### // 索引 $table->unique('email'); $table->index(['account_id', 'created_at']); $table->primary('id'); $table->primary(['user_id', 'role_id']); ``` ## 表填充 参考DatabaseSeeder.php文件 faker官网 > https://fakerphp.github.io faker总结 https://learnku.com/articles/39833 ## 测试faker ```bash // 进入 tinker 模式 $ php artisan tinker // 获取 Faker 实例 $faker >>> $faker = app(Faker\Generator::class); // 查看 faker 数据 >>> $faker->name() >>> $faker->email() >>> $faker->sentence() ```