<?php

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

class AddForeignKeysToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->foreignId('prefix_id')->after('id')->references('id')->on('prefixes')->onDelete('cascade');
            $table->foreignId('position_id')->after('prefix_id')->references('id')->on('positions')->onDelete('cascade');
            $table->foreignId('sector_id')->after('position_id')->references('id')->on('sectors')->onDelete('cascade');
            $table->foreignId('extension_id')->after('sector_id')->references('id')->on('extensions')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropForeign(['prefix_id']);
            $table->dropColumn(['prefix_id']);
            $table->dropForeign(['position_id']);
            $table->dropColumn(['position_id']);
            $table->dropForeign(['sector_id']);
            $table->dropColumn(['sector_id']);
            $table->dropForeign(['extension_id']);
            $table->dropColumn(['extension_id']);
        });
    }
}
