update($request->safe()->except('positions')); foreach ($request->validated('positions') as $position) { if ($position['id']) { $invoice->positions()->firstWhere('id', $position['id'])->update(Arr::except($position, 'id')); continue; } $invoice->positions()->create($position); } $invoice->positions()->whereNotIn('id', array_column($request->validated('positions'), 'id'))->delete(); Succeeded::message('Rechnung bearbeitet.')->dispatch(); } }