<?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(): void
    {
        Schema::table('event_product', function (Blueprint $table) {
            // Drop foreign key constraint before dropping the column
            $table->dropForeign(['event_id']);
            $table->dropColumn('event_id');
            $table->integer('quantity')->after('user_id');
            $table->unsignedBigInteger('product_id')->after('id');
            $table->foreign('product_id')->references('id')->on('product')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('event_product', function (Blueprint $table) {
            $table->unsignedBigInteger('event_id')->after('id');
            $table->dropColumn('product_id');
        });
    }
};
