<?php

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

class ModifyDeductionDateInSalaryDeductions extends Migration
{
    public function up()
    {
        Schema::table('salary_deductions', function (Blueprint $table) {
            // Make deduction_date nullable or set a default value
            if (Schema::hasColumn('salary_deductions', 'deduction_date')) {
                $table->date('deduction_date')->nullable()->default(null)->change();
            } else {
                $table->date('deduction_date')->nullable()->after('reason');
            }
        });
    }

    public function down()
    {
        Schema::table('salary_deductions', function (Blueprint $table) {
            if (Schema::hasColumn('salary_deductions', 'deduction_date')) {
                $table->date('deduction_date')->nullable(false)->default(now())->change();
            }
        });
    }
}