Files
erahn-click/app/Console/Commands/DeleteCarts.php
T
2025-01-13 00:29:47 +08:00

54 lines
1.1 KiB
PHP

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