Files
erahn-click/app/Console/Commands/DeleteCartsHourly.php
T

56 lines
1.2 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\PersonalCarts;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class DeleteCartsHourly extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'carts:hourlydelete';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Soft Delete all carts hourly';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
try{
$oneHourAgo = Carbon::now()->subHour();
$deleted = PersonalCarts::where('created_at', '<', $oneHourAgo)->delete();
Log::info('carts hourly have been deleted.');
$this->info('carts have been deleted.');
}catch(\Exception $e){
Log::error('Error deleting hourly carts: ' . $e->getMessage());
$this->error('Error deleting hourly carts: ' . $e->getMessage());
return 1;
}
}
}