Skip to content

Commit

Permalink
Cascade user delete to row in pivot table
Browse files Browse the repository at this point in the history
  • Loading branch information
alexblunck committed May 4, 2018
1 parent 8af0e09 commit cabe8c4
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class ModifyUserIdForeignKeyOnPivotTable extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::table('coupon_user', function (Blueprint $table) {
$table->dropForeign(['user_id']);
});

Schema::table('coupon_user', function (Blueprint $table) {
$table->foreign('user_id')
->references('id')->on('users')
->onDelete('cascade');
});
}

/**
* Reverse the migrations.
*/
public function down()
{
Schema::table('coupon_user', function (Blueprint $table) {
$table->dropForeign(['user_id']);
});

Schema::table('coupon_user', function (Blueprint $table) {
$table->foreign('user_id')->references('id')->on('users');
});
}
}

0 comments on commit cabe8c4

Please sign in to comment.