adrema/database/migrations/2026_06_19_225430_update_in...

45 lines
1.2 KiB
PHP

<?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
{
foreach (DB::table('invoices')->get() as $invoice) {
$to = json_decode($invoice->to);
$position = DB::table('invoice_positions')->where('invoice_id', $invoice->id)->first();
if ($position) {
$member = DB::table('members')->where('id', $position->member_id)->first();
if ($member) {
$to->email = $member->email_parents ?: $member->email;
}
}
$to->greeting = 'Liebe '.$to->name;
DB::table('invoices')->where('id', $invoice->id)->update(['to' => json_encode($to)]);
}
Schema::table('invoices', function (Blueprint $table) {
$table->dropColumn('greeting');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('invoices', function (Blueprint $table) {
$table->string('greeting');
});
}
};