Edit File: CancelOldOrders.php
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\Order; use Carbon\Carbon; class CancelOldOrders extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'orders:cancel-old'; /** * The console command description. * * @var string */ protected $description = 'Cancel orders that were created 20 minutes ago or more'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return int */ public function handle() { $cutoffTime = Carbon::now()->subMinutes(20); $orders = Order::where('payment_status', 'false') ->where('created_at', '<=', $cutoffTime) ->update(['status' => 'closed']); $this->info("Old orders canceled successfully."); } }
Back to File Manager