Available for select projects New York · Working worldwide
Rappasoft LLC
Menu
Loading snippet

Library / Snippet

Use artisan model:prune to Auto-Clean Old Records

Laravel Eloquent

Want to delete old logs or temporary records?

In your model:

1use Illuminate\Database\Eloquent\Prunable;
2 
3public function prunable()
4{
5 return $this->where('created_at', '<', now()->subMonth());
6}

Then add this to your schedule:

1$schedule->command('model:prune')->daily();

This will remove the records that are older than 1 month.