From af6c751ede83b0ed1732b2b4abb6c813dd4e1ecc Mon Sep 17 00:00:00 2001 From: adonis Date: Sun, 5 Jul 2026 21:17:21 +0330 Subject: [PATCH] added pargar 3 --- ...07_05_000002_create_pargar_integration.php | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/database/migrations/2026_07_05_000002_create_pargar_integration.php b/database/migrations/2026_07_05_000002_create_pargar_integration.php index 46b284c..7ad7f0d 100644 --- a/database/migrations/2026_07_05_000002_create_pargar_integration.php +++ b/database/migrations/2026_07_05_000002_create_pargar_integration.php @@ -6,6 +6,18 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { + /** @param list $candidates */ + private function firstExistingColumn(string $table, array $candidates): ?string + { + foreach ($candidates as $column) { + if (Schema::hasColumn($table, $column)) { + return $column; + } + } + + return null; + } + public function up(): void { if (! Schema::hasTable('pargar_sync_logs')) { @@ -28,14 +40,36 @@ return new class extends Migration } if (Schema::hasTable('customers') && ! Schema::hasColumn('customers', 'pargar_account_id')) { - Schema::table('customers', function (Blueprint $table) { - $table->string('pargar_account_id', 64)->nullable()->after('moshtari_code'); + $afterColumn = $this->firstExistingColumn('customers', [ + 'moshtari_code', + 'tahesab_id', + 'finance_code', + 'pargar_id', + 'mobile', + ]); + + Schema::table('customers', function (Blueprint $table) use ($afterColumn) { + if ($afterColumn !== null) { + $table->string('pargar_account_id', 64)->nullable()->after($afterColumn); + } else { + $table->string('pargar_account_id', 64)->nullable(); + } }); } if (Schema::hasTable('orders') && ! Schema::hasColumn('orders', 'pargar_confirmed_at')) { - Schema::table('orders', function (Blueprint $table) { - $table->timestamp('pargar_confirmed_at')->nullable()->after('pay_at'); + $afterColumn = $this->firstExistingColumn('orders', [ + 'pay_at', + 'sts', + 'updated_at', + ]); + + Schema::table('orders', function (Blueprint $table) use ($afterColumn) { + if ($afterColumn !== null) { + $table->timestamp('pargar_confirmed_at')->nullable()->after($afterColumn); + } else { + $table->timestamp('pargar_confirmed_at')->nullable(); + } }); } }