我正在用laravel建立門票系統。但是當我取消票時,反應不會消失?laravel cascade不工作?
這是我的數據透視表的遷移:
public function up()
{
Schema::create('reactions_ticket',function(Blueprint $table)
{
$table->integer('ticket_id')->unsigned();
$table->foreign('ticket_id')->references('id')->on('ticket')->onDelete('cascade');
$table->integer('reactions_id')->unsigned();
$table->foreign('reactions_id')->references('id')->on('reactions')->onDelete('cascade');
});
}
這是我的反應表:
public function up()
{
Schema::create('reactions',function(Blueprint $table)
{
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->text('content');
$table->timestamps();
});
}
和我的票表:
public function up()
{
Schema::create('ticket',function(Blueprint $table)
{
$table->increments('id');
$table->string('slug')->nullable();
$table->integer('ticketid')->unsigned();
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->integer('subject_id')->unsigned();
$table->foreign('subject_id')->references('id')->on('subject')->onDelete('cascade');
$table->integer('websites_id')->unsigned();
$table->foreign('websites_id')->references('id')->on('websites')->onDelete('cascade');
$table->integer('status_id')->unsigned();
$table->foreign('status_id')->references('id')->on('status')->onDelete('cascade');
$table->text('content');
$table->timestamps();
});
}
我在做什麼錯>?
你有softDeleting嗎? – ceejayoz
感謝您的回覆。但爲什麼我應該這樣做?我只想刪除與該票相關的所有內容。當我去laravel docs時,它告訴我關於softDeleting的這個問題:「當軟刪除一個模型時,它實際上並沒有從你的數據庫中刪除。」這不是我想要的。 – Jamie
如果你對'tickets'模型有softDeleting,那麼調用'delete()'就不會刪除它的關係。 – ceejayoz