added command for deleted personal carts

This commit is contained in:
hafifierahman
2025-01-13 00:29:47 +08:00
parent 7b7a47b13e
commit 1073f5f1f9
+53
View File
@@ -0,0 +1,53 @@
<?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;
}
}
}