1.执行命令
1 php artisan make:model Answer –cmrf
一次性把model,及对应的controller migration factory 创建好,并且controller配置设置为resource
2.修改****_**_**_******_create_answers_table.php:
1 <?php 2 3 use Illuminate\Database\Migrations\Migration; 4 use Illuminate\Database\Schema\Blueprint; 5 use Illuminate\Support\Facades\Schema; 6 7 class CreateAnswersTable extends Migration 8 { 9 /** 10 * Run the migrations. 11 * 12 * @return void 13 */ 14 public function up() 15 { 16 Schema::create('answers', function (Blueprint $table) { 17 $table->bigIncrements('id'); 18 $table->unsignedBigInteger('user_id')->index()->comment("答案是哪个用户创建的"); 19 $table->unsignedBigInteger('question_id')->index()->comment("答案是回答的哪个问题"); 20 $table->text('content')->comment("答案的具体内容"); 21 $table->integer('votes_count')->default(0)->comment("点赞总数"); 22 $table->integer('comments_count')->default(0)->comment("回复总数"); 23 $table->string('is_hidden', 8)->default("F")->comment("回答状态是否被隐藏,默认设置长度必须大于8");//默认设置长度必须大于8,否则不被赋值F,即被隐藏 24 $table->string('close_comment')->default('F')->comment("回答是否被关闭评论");//默认F代表否,即不关闭,如果需要关闭设置为 T 25 $table->softDeletes()->comment("支持软删除"); 26 $table->timestamps(); 27 }); 28 } 29 30 /** 31 * Reverse the migrations. 32 * 33 * @return void 34 */ 35 public function down() 36 { 37 Schema::dropIfExists('answers'); 38 } 39 }