option('dry-run'); $query = OrderItem::whereNull('expiry_date') ->whereNotNull('months') ->where('months', '>', 0); $count = $query->count(); if ($count === 0) { $this->info('No order items need to be updated.'); return 0; } $this->info("Found {$count} order items to update."); if ($dryRun) { $this->warn('DRY RUN - No changes will be made.'); $query->chunk(100, function ($items) { foreach ($items as $item) { $expiryDate = Carbon::parse($item->created_at)->addMonths($item->months); $this->line("Order #{$item->order_id}, Item #{$item->id}: would set expiry_date to {$expiryDate}"); } }); } else { $updated = 0; $query->chunk(100, function ($items) use (&$updated) { foreach ($items as $item) { $expiryDate = Carbon::parse($item->created_at)->addMonths($item->months); $item->update(['expiry_date' => $expiryDate]); $updated++; } }); $this->info("Updated {$updated} order items."); } return 0; } }