-
app/Console/Commands/RemoveOldCarts.php
Open in GitHubuse App\Cart; use Illuminate\Console\Command; class RemoveOldCarts extends Command { protected $signature = 'carts:remove-old {--days=7 : The days after which the carts will be removed}'; protected $description = 'Remove the old carts based on a given days.'; public function __construct() { parent::__construct(); } public function handle() { $deadline = now()->subDays($this->option('days')); $counter = Cart::whereDate('updated_at', '<=', $deadline)->delete(); $this->info("Done! {$counter} carts were removed."); } }