1.执行命令:
1 php artisan make:model Models/Question -cm
1 <?php 2 3 use IlluminateDatabaseMigrationsMigration; 4 use IlluminateDatabaseSchemaBlueprint; 5 use IlluminateSupportFacadesSchema; 6 7 class CreateQuestionsTable extends Migration 8 { 9 /** 10 * Run the migrations. 11 * 12 * @return void 13 */ 14 public function up() 15 { 16 Schema::create('questions', function (Blueprint $table) { 17 $table->bigIncrements('id'); 18 $table->string('title'); 19 $table->text('content'); 20 $table->integer('comments_count')->default(0); 21 $table->integer('followers_count')->default(1);//问题的关注者数量,默认1个【提问的人就是最开始关注的那个人】 22 $table->integer('answers_count')->default(0); 23 $table->string('close_comment', 8)->default('F');//问题是否被关闭评论 F默认否 24 $table->string('is_hidden', 8)->default('F');//问题是否被隐藏 F默认否 25 $table->timestamps(); 26 }); 27 } 28 29 /** 30 * Reverse the migrations. 31 * 32 * @return void 33 */ 34 public function down() 35 { 36 Schema::dropIfExists('questions'); 37 } 38 } 39
上面的default(‘F’) 真就是’T’,不过有些习惯使用smallInterger然后默认设置值为0 ,真为1的方式也可以。
3. 执行命令:
1 php artisan migrate