Skip to main content

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

Read more here

spatie/laravel-comments.com

10 stars
1 code files
View spatie/laravel-comments.com on GitHub

app/Console/Commands/DeleteOldComments.php

Open in GitHub
use App\Models\Post;
use Illuminate\Console\Command;
use Spatie\Comments\Models\Comment;
 
class DeleteOldComments extends Command
{
protected $signature = 'delete-old-comments-and-posts';
 
public function handle()
{
Comment::query()->where('created_at','<=', now()->subHour())->delete();
Post::query()->where('created_at','<=', now()->subHour())->delete();
 
$this->info('All done!');
}
}

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.