<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
public function up()
{
    Schema::table('questions', function (Blueprint $table) {

        // 🔥 أول شيء نحذف الـ foreign key
        $table->dropForeign(['category_id']);

        // 🔥 بعدين نحذف العمود
        $table->dropColumn('category_id');

        // 🔥 نضيف الجديد
        $table->foreignId('sub_category_id')
            ->constrained()
            ->onDelete('cascade');
    });
}

    /**
     * Reverse the migrations.
     */
  public function down()
{
    Schema::table('questions', function (Blueprint $table) {

        $table->dropForeign(['sub_category_id']);
        $table->dropColumn('sub_category_id');

        $table->foreignId('category_id')
            ->constrained()
            ->onDelete('cascade');
    });
}
};
