myparcelcom/resource-cleanup

Clean up soft-deleted and expired records from your Laravel application after a configurable cutoff date.

Maintainers

Package info

github.com/MyParcelCOM/resource-cleanup

pkg:composer/myparcelcom/resource-cleanup

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 1

dev-master 2026-05-07 08:48 UTC

This package is not auto-updated.

Last update: 2026-05-08 02:35:50 UTC


README

Tests

A Laravel package to permanently delete soft-deleted or expired records based on a defined "cleanable" query scope or after a configurable cutoff date.

Requirements

  • PHP 8.2+
  • Laravel 9, 10, 11, or 12

Installation

composer require myparcelcom/resource-cleanup

Publish the config file:

php artisan vendor:publish --tag=resource-cleanup-config

Configuration

config/resource-cleanup.php:

return [
    // Records older than this many days will be deleted (default: 90)
    'default_retention_days' => env('RESOURCE_CLEANUP_RETENTION_DAYS', 90),

    // Valid models to clean up
    'models' => [
        \App\Models\Order::class,
        \App\Models\AuditLog::class,
    ],
];

Usage

Artisan Command

Run cleanup for all models defined in the config:

php artisan resource-cleanup:run

Target specific models from the config:

php artisan resource-cleanup:run --model=App\\Models\\Order

Preview what would be deleted without deleting anything:

php artisan resource-cleanup:run --dry-run

Per-Model Cutoff Dates

Implement the CleanableResource contract on any model to define its own retention period:

use Illuminate\Database\Eloquent\Builder;
use MyParcelCom\ResourceCleanup\Contracts\CleanableResource;

class AuditLog extends Model implements CleanableResource
{
    public static function scopeCleanable(): Builder
    {
        // narrow down the query scope by adding where() clauses
        return self::query();
    }
}

Testing

With Docker (recommended)

Build the container and run the test suite:

docker compose run --rm app

Run a specific test or filter:

docker compose run --rm app vendor/bin/phpunit --filter test_it_deletes_soft_deleted_records

Drop into a shell inside the container:

docker compose run --rm app bash

Run Composer commands without installing PHP locally:

docker compose run --rm app composer require some/package

Without Docker

composer install
composer test