$record->id, 'packing_id' => $size['packing_id'], 'description' => $size['description'] ?? null, 'price' => $size['price'], 'sku' => $size['sku'] ?? null, 'gtin' => $size['gtin'] ?? null, ]); } $spices = $data['recipe_spices'] ?? []; if (! empty($spices)) { $recipe = Recipe::create([ 'name' => $data['title'], 'product_id' => $record->id, 'version' => 1, ]); $pivotData = collect($spices)->mapWithKeys(fn ($s) => [ $s['spice_id'] => ['amount_in_percent' => $s['amount_in_percent']], ])->toArray(); $recipe->spices()->sync($pivotData); $record->update(['recipes_id' => $recipe->id]); } return $record; } }