<?php

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

return new class extends Migration {
    public function up()
    {
        Schema::table('bookings', function (Blueprint $table) {
            // Drop old foreign key
            $table->dropForeign(['passenger_id']);
            // Add new foreign key to users table
            $table->foreign('passenger_id')->references('id')->on('users')->onDelete('set null');
        });
    }

    public function down()
    {
        Schema::table('bookings', function (Blueprint $table) {
            $table->dropForeign(['passenger_id']);
            $table->foreign('passenger_id')->references('id')->on('passengers')->onDelete('set null');
        });
    }
};
