-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cascade user delete to row in pivot table
- Loading branch information
1 parent
8af0e09
commit cabe8c4
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
migrations/2018_05_04_000000_modify_user_id_foreign_key_on_pivot_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
} | ||
} |