examples/RealWorldExample.php
public function syncExistingWastageItems(WastageModel $wastage, Collection $products, array $items)
    {
        $itemModels = [];

        foreach ($items as $key => $value) {
            if ($item = $this->findProductItem($wastage->items, $key)) {
                $this->checkIntegrity($item);
                $item->update($value);
            } else {
                $data = $this->buildItemData($key, $value, $products);
                $item = $this->create($data);
            }

            $itemModels[] = $item;
        }

        return $itemModels;
    }
public function syncExistingWastageItems(WastageModel $wastage, Collection $products, array $items)
    {
        $itemModels = [];

        foreach ($items as $key => $value) {
            if ($item = $this->findProductItem($wastage->items, $key)) {
                $this->checkIntegrity($item);
                $item->update($value);
            } else {
                $data = $this->buildItemData($key, $value, $products);
                $item = $this->create($data);
            }

            $itemModels[] = $item;
        }

        return $itemModels;
    }
Sync items for an existing wastage. Updates the item entry if it exists,
or creates them if they don't.

@param  \REDACTED\Wastage\WastageModel            $wastage
@param  \Illuminate\Database\Eloquent\Collection  $products
@param  array                                     $items    Item input

@return array  Array of WastageItem models