Laravel Vuejs 實戰:開發知乎 (5)設計問題表

1.執行命令:php

  1 php artisan make:model Models/Question -cm
2.設計問題的數據庫遷移文件中的字段:
  1 <?php
  2 
  3 use Illuminate\Database\Migrations\Migration;
  4 use Illuminate\Database\Schema\Blueprint;
  5 use Illuminate\Support\Facades\Schema;
  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. 執行命令:ide

  1 php artisan migrate
相關文章
相關標籤/搜索