<?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('rekomendasis', function (Blueprint $table) {
        if (!Schema::hasColumn('rekomendasis', 'komponen_id')) {
            $table->foreignId('komponen_id')->after('makanan_id')->constrained('komponens')->cascadeOnDelete();
        }

        if (!Schema::hasColumn('rekomendasis', 'waktu_makan_id')) {
            $table->foreignId('waktu_makan_id')->after('komponen_id')->constrained('waktu_makans')->cascadeOnDelete();
        }
    });
}


    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('rekomendasis', function (Blueprint $table) {
             $table->dropForeign(['komponen_id']);
            $table->dropForeign(['waktu_makan_id']);
            $table->dropColumn(['komponen_id', 'waktu_makan_id']);
        });
    }
};
