Spaces:
Sleeping
Sleeping
File size: 753 Bytes
10dc6f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php
namespace App\Console\Commands;
use App\Models\Order;
use App\Services\OrderService;
use Illuminate\Console\Command;
class ExpirePendingOrders extends Command
{
protected $signature = 'orders:expire-pending';
protected $description = 'Expire pending orders that have passed their expiry time and restore stock';
public function handle(OrderService $orderService): int
{
$orders = Order::where('status', 'pending')
->where('expires_at', '<', now())
->get();
$count = 0;
foreach ($orders as $order) {
$orderService->expireOrder($order);
$count++;
}
$this->info("Expired {$count} pending orders.");
return Command::SUCCESS;
}
}
|