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'); }); } };