Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

JuanDMeGon/Laravel-from-Scratch

17 stars
1 code files
View JuanDMeGon/Laravel-from-Scratch on GitHub

app/Console/Commands/RemoveOldCarts.php

Open in GitHub
use 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.");
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.