<?php

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

class AlterColumnsInMemberUsersTableToCascadeOnDelete extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('member_users', function (Blueprint $table) {
            $table->dropForeign(['member_id']);
            $table->foreign(['member_id'])
                ->references('id')
                ->on('members')
                ->cascadeOnDelete();

            $table->dropForeign(['user_id']);
            $table->foreign(['user_id'])
                ->references('id')
                ->on('users')
                ->cascadeOnDelete();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('member_users', function (Blueprint $table) {
            $table->dropForeign(['member_id']);
            $table->foreign(['member_id'])->references('id')->on('members');

            $table->dropForeign(['user_id']);
            $table->foreign(['user_id'])->references('id')->on('users');
        });
    }
}
