zhouxiaoshuai3

6480 经验值

我感觉删除的时候,那个关系表question_topic可以连同一起删除对应的数据。但是话题表topics没要一同删除吧???

那就设置外键就行了

public function up()
    {
        Schema::create('question_topic', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('question_id')->unsigned()->index();
            $table->integer('topic_id')->unsigned()->index();
            $table->foreign('question_id')->references('id')->on('questions')->onDelete('cascade');
            $table->foreign('topic_id')->references('id')->on('topics')->onDelete('cascade');
            $table->timestamps();
        });
    }
<?php
 echo 'laravel5';
//测试一下
?>