定制 naviisml/laravel-reaper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

naviisml/laravel-reaper

Composer 安装命令:

composer require naviisml/laravel-reaper

包简介

Automatic, rule-based purging of Eloquent models.

README 文档

README

Automatic, rule-based purging of Eloquent models.

Reaper is a Laravel package that safely and declaratively force-deletes soft-deleted models after configurable grace periods — with support for:

  • ⏱ Simple retention periods (30d)
  • 🧩 Composite periods (3w10d1h)
  • 🔗 Multiple conditions (last_activity + deleted_at)
  • 🔀 AND / OR logic
  • 🧠 Custom purge conditions
  • ⏰ Scheduler-driven + manual execution

Features

  • One global scheduler — no per-model cron jobs
  • Declarative purge rules on models — custom condition evaluation logic
  • Custom purge conditions (closures or classes)
  • Chunked & queue-safe

Installation

composer require naviisml/laravel-reaper

Laravel will auto-discover the service provider.

🚀 Quick Start

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Naviisml\Reaper\Concerns\IsReapable;

class User extends Model
{
    use SoftDeletes;
    use IsReapable;

    protected string $period = '30d';
}

That’s it.

Reaper will automatically force-delete users that have been soft-deleted for more than 30 days.

Supported Period Format

Reaper uses a compact, human-readable period syntax:

Unit Meaning
h hours
d days
w weeks
m months
y years (optional extension)

Examples

30d
12h
3w10d1h
1y2m

Advanced Retention Rules

Note: If all the fields match, but the model is not yet soft deleted, the model will first be soft deleted. If the model doesnt support soft deletes, it will be deleted.

Multiple conditions (AND by default)

protected array $periods = [
    'last_activity' => '1y',
    'deleted_at'    => '1m',
];

Meaning:

last_activity <= now() - 1 year
AND
deleted_at    <= now() - 1 month

Purge Rules

For complex rules, define a $purge definition.

AND (explicit)

protected array $purge = [
    'and' => [
        ['column' => 'deleted_at', 'older_than' => '30d'],
        ['column' => 'last_login', 'older_than' => '1y'],
    ],
];

OR

protected array $purge = [
    'or' => [
        ['column' => 'deleted_at', 'older_than' => '6m'],
        ['column' => 'bounced_at', 'older_than' => '7d'],
    ],
];

Nested conditions

protected array $purge = [
    'and' => [
        ['column' => 'deleted_at', 'older_than' => '30d'],
        [
            'or' => [
                ['column' => 'last_activity', 'older_than' => '1y'],
                ['column' => 'last_login',    'older_than' => '18m'],
            ],
        ],
    ],
];

Closure-based

protected array $purge = [
    'and' => [
        fn ($query) => $query->whereNull('subscription_id'),
        ['column' => 'deleted_at', 'older_than' => '14d'],
    ],
];

Class-based

protected array $purge = [
    'and' => [
        \App\Purge\InactiveTrialCondition::class,
        ['column' => 'deleted_at', 'older_than' => '14d'],
    ],
];
class InactiveTrialCondition
{
    public function apply($query): void
    {
        $query->where('trial_ended', true);
    }
}

Scheduler

Reaper automatically registers a scheduled job:

  • Runs hourly
  • Uses withoutOverlapping()
  • Chunked deletes (chunkById)
  • Queue-safe

Make sure Laravel’s scheduler is running:

* * * * * php artisan schedule:run

Commands

Run Purge Manually

Dispatch via queue (default)

php artisan reaper:purge

Run synchronously (debug / CI)

php artisan reaper:purge --sync

📄 License

MIT © Naviisml

naviisml/laravel-reaper 适用场景与选型建议

naviisml/laravel-reaper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 naviisml/laravel-reaper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 naviisml/laravel-reaper 我们能提供哪些服务?
定制开发 / 二次开发

基于 naviisml/laravel-reaper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-21