<?php

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

class CreateArrearsCollectionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('arrears_collections', function (Blueprint $table) {
            $table->id();
            $table->date('months');
            $table->unsignedBigInteger('payment_id')->nullable();
            $table->unsignedBigInteger('member_id')->nullable();
            $table->unsignedBigInteger('cover_id')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->foreign('payment_id')
                ->references('id')
                ->on('premium_payments')
                ->onDelete('cascade');

            $table->foreign('member_id')
                ->references('id')
                ->on('members')
                ->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        // Schema::dropIfExists('arrears_collections');
        Schema::table('arrears_collections', function (Blueprint $table) {
            $table->dropSoftDeletes();
        });
    }
}
