format('Y-m-d')) ->lockForUpdate() ->count(); $sequence = str_pad($lastOrder + 1, 3, '0', STR_PAD_LEFT); $order->order_number = 'ORD-'.now()->format('Ymd').'-'.$sequence; $order->user_id = auth()->id(); $order->total = $order->subtotal - $order->discount; } /** * Handle the Order "deleting" event. */ public function deleting(Order $order): void { foreach ($order->items as $item) { $item->product->increment('stock', $item->qty); } } }