<?php

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

class CreateAddressesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('addresses', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('member_id');
            $table->string('indicating')->nullable();
            $table->enum('type', ['main', 'visiting', 'invoice', 'other']);
            $table->string('first_name_contact_person')->nullable();
            $table->string('last_name_contact_person')->nullable();
            $table->string('infix')->nullable();
            $table->string('email')->nullable();
            $table->string('address')->nullable();
            $table->string('postal')->nullable();
            $table->string('phone')->nullable();
            $table->string('city')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

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

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

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