<?php

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

class AddForeignKeyToHcpEducation extends Migration
{
    public function up()
    {
        Schema::table('hcp_education', function (Blueprint $table) {
            if (!Schema::hasColumn('hcp_education', 'hcp_id')) {
                $table->unsignedBigInteger('hcp_id');
            }

            $table->foreign('hcp_id')
                  ->references('hcp_id')->on('hcp')
                  ->onUpdate('cascade')
                  ->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::table('hcp_education', function (Blueprint $table) {
            $table->dropForeign(['hcp_id']);
            
        });
    }
}
