```php increments('id'); $table->string('topic'); $table->unsignedInteger('exam_id'); $table->foreign('exam_id')->references('id')->on('exams')->onDelete('cascade'); $table->string('opt1'); $table->string('opt2'); $table->string('opt3'); $table->string('opt4'); $table->unsignedTinyInteger('ans'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('topics'); } } ``` ``` 3. `topic`:題目 4. `exam_id`:對應的測驗編號 5. `opt1`~`opt4`:選項1~4 6. `ans`:正確解答 7. 其中 20 行的 `onDelete('cascade')` 是一個約束條件,也就是當測驗刪除時,連同題目也一併刪除之意。 詳情: 8. 最後執行資料庫遷移即可建出新的資料表 ```bash php artisan migrate ``` 9. 一樣看一下是否有建立出來 [](https://github.com/tad0616/exam56/commit/caf406ca44883f94e8c0602ac117c182c1fffb20)
進階搜尋