id)->get(); $arr = []; foreach ($objekte_im_detail as $row) { $arr[] = $row->raumart; ProjektMethode::firstOrCreate([ 'projekte_id' => $record->id, 'raumart' => $row->raumart, ]); } ProjektMethode::where('projekte_id', $record->id)->whereNotIn('raumart', $arr)->delete(); } }