<?php

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

class CreateContactsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('contacts', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('member_id');
            $table->string('function')->nullable();
            $table->string('salutation_cp')->nullable();
            $table->string('initials_cp')->nullable();
            $table->string('lastname_cp')->nullable();
            $table->string('email_cp')->nullable();
            $table->string('email2_cp')->nullable();
            $table->string('phone_cp')->nullable();
            $table->string('address_cp')->nullable();
            $table->string('postal_cp')->nullable();
            $table->string('city_cp')->nullable();
            $table->string('salutation_cc')->nullable();
            $table->string('initials_cc')->nullable();
            $table->string('lastname_cc')->nullable();
            $table->string('email_cc')->nullable();
            $table->string('email2_cc')->nullable();
            $table->string('phone_cc')->nullable();
            $table->string('address_cc')->nullable();
            $table->string('postal_cc')->nullable();
            $table->string('city_cc')->nullable();
            $table->timestamps();
        });

        Schema::table('contacts', function (Blueprint $table) {
            $table->foreign('member_id')->references('id')->on('members')->onDelete('cascade');
        });
    }

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

        Schema::dropIfExists('contacts');
    }
}
