Edit File: MakeOrderCancelled.php
<?php namespace App\Console\Commands; use App\Enums\NotificationTypeEnum; use App\Enums\OrderStatusEnum; use App\Models\Order; use App\Notifications\OrderNotification; use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Support\Facades\Notification; class MakeOrderCancelled extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'order:make-cancelled'; /** * The console command description. * * @var string */ protected $description = 'make the status of order cancelled When the specified period for acceptance passes and this is not done'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return int */ public function handle() { $orders = Order::whereStatus(OrderStatusEnum::New->value)->get(); foreach ($orders as $order) { if (Carbon::parse($order->expired_at) < Carbon::now()) { $order->update([ 'status' => OrderStatusEnum::Cancelled->value ]); Notification::send($order->user, new OrderNotification($order, NotificationTypeEnum::Cancelled->value)); } } } }
Back to File Manager