public function store(Request $request) { // ... // iterate (loop) over each item in the order items collection $order->items->each(function ($item) { // deduct the quantity of the item for this order // from the stock of the product and update the new stock $item->update(['stock' => ($item->stock - $item->pivot->quantity)]); }); // ... }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter