<?php

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

return new class extends Migration {
    public function up(): void
    {
        Schema::table('chl_voucher', function (Blueprint $table) {
            $table->unsignedBigInteger('PayMd_ID')->nullable()->after('your_column_name');

            $table->foreign('PayMd_ID')
                  ->references('PayMd_ID')
                  ->on('payment_modes')
                  ->onDelete('set null'); // important for nullable FK
        });
    }

    public function down(): void
    {
        Schema::table('chl_voucher', function (Blueprint $table) {
            $table->dropForeign(['PayMd_ID']);
            $table->dropColumn('PayMd_ID');
        });
    }
};
