examples/RealWorldExample.php
protected function buildItemData($key, array $data, Collection $products)
    {
        if (!$product = $products->find($key)) {
            throw new \RuntimeException("ID $key not found in products collection");
        }

        $this->setProduct($product);

        if (!empty($data['purchased_amount'])) {
            $data['purchased_for'] = $product->in_price;
        }

        if (!empty($data['sold_amount'])) {
            $data['sold_for'] = $product->out_price;
        }

        return $data;
    }
protected function buildItemData($key, array $data, Collection $products)
    {
        if (!$product = $products->find($key)) {
            throw new \RuntimeException("ID $key not found in products collection");
        }

        $this->setProduct($product);

        if (!empty($data['purchased_amount'])) {
            $data['purchased_for'] = $product->in_price;
        }

        if (!empty($data['sold_amount'])) {
            $data['sold_for'] = $product->out_price;
        }

        return $data;
    }
Build the pivot table data for a particular item.

@param  mixed                                    $key      The product's primary key.
@param  array                                    $data
@param  \Illuminate\Database\Eloquent\Collection $products

@return array