This package will clean up unneeded records for your Eloquent models.

The only things you have to do is let your models implement the GetsCleanedUp-interface and scheduled a command that performs the cleanup.

Here's a quick example of a model that implements GetsCleanedUp:

use Spatie\ModelCleanup\GetsCleanedUp;
use Illuminate\Database\Eloquent\Builder;
use Carbon\Carbon;

class LogItem extends Model implements GetsCleanedUp
{
    ...

     public static function cleanUp(Builder $query) : Builder
     {
        //delete up all records older than a year
        return $query->where('created_at', '<', Carbon::now()->subYear());
     }
}

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on their website.