option('minutes')); $limit = max(1, (int) $this->option('limit')); $threshold = now()->subMinutes($minutes); $orders = Order::withoutGlobalScopes() ->where('status', Order::STATUS_PENDING) ->where('created_at', '<', $threshold) ->orderBy('id') ->limit($limit) ->get(); if ($orders->isEmpty()) { $this->info('No stale pending orders to sweep.'); return self::SUCCESS; } $swept = 0; foreach ($orders as $order) { $order->update(['status' => Order::STATUS_ABANDONED]); $swept++; } Log::info('Swept abandoned orders', ['count' => $swept, 'older_than_minutes' => $minutes]); $this->info("Marked {$swept} pending order(s) as abandoned (older than {$minutes} min)."); return self::SUCCESS; } }