diff --git a/database/migrations/2026_11_18_000001_update_sms_templates_unit_to_kilogram.php b/database/migrations/2026_11_18_000001_update_sms_templates_unit_to_kilogram.php index 11144e5..7e49561 100644 --- a/database/migrations/2026_11_18_000001_update_sms_templates_unit_to_kilogram.php +++ b/database/migrations/2026_11_18_000001_update_sms_templates_unit_to_kilogram.php @@ -11,7 +11,7 @@ return new class extends Migration */ public function up(): void { - if (Schema::hasTable('settings')) { + if (Schema::hasTable('settings') && Schema::hasColumn('settings', 'value')) { $rows = DB::table('settings') ->where(function ($q) { $q->where('key', 'like', '%sms%') @@ -38,19 +38,46 @@ return new class extends Migration } if (Schema::hasTable('automations')) { - $autos = DB::table('automations')->where('message', 'like', '%گرم%')->get(); - foreach ($autos as $auto) { - $msg = (string) ($auto->message ?? ''); - $updated = preg_replace( - '/(?where('id', $auto->id)->update([ - 'message' => $updated, - 'updated_at' => now(), - ]); + $column = null; + if (Schema::hasColumn('automations', 'body')) { + $column = 'body'; + } elseif (Schema::hasColumn('automations', 'message')) { + $column = 'message'; + } + + if ($column !== null) { + $autos = DB::table('automations')->where($column, 'like', '%گرم%')->get(); + foreach ($autos as $auto) { + $msg = (string) ($auto->{$column} ?? ''); + $updated = preg_replace( + '/(?where('id', $auto->id)->update([ + $column => $updated, + 'updated_at' => now(), + ]); + } + } + } + + if (Schema::hasColumn('automations', 'title')) { + $autos = DB::table('automations')->where('title', 'like', '%گرم%')->get(); + foreach ($autos as $auto) { + $title = (string) ($auto->title ?? ''); + $updated = preg_replace( + '/(?where('id', $auto->id)->update([ + 'title' => $updated, + 'updated_at' => now(), + ]); + } } } }