Product Decisions This Supports
- Compliance & Auditability: Enables regulatory compliance (e.g., GDPR, SOX) by tracking full history of Eloquent model changes with timestamps, user context, and metadata. Justifies "why" and "when" changes occurred.
- Undo/Redo Functionality: Powers time-travel debugging, user self-service corrections (e.g., "I accidentally deleted this record"), or admin overrides (e.g., "Restore this order to its shipped state").
- Data Lineage: Supports complex workflows where state transitions (e.g., order status:
pending → shipped) must be queryable independently of other attribute changes.
- Build vs. Buy: Eliminates need to build custom versioning tables, diff logic, or snapshot storage. Reduces technical debt vs. rolling your own solution.
- Feature Roadmap:
- Time-based rollback: "Revert all changes made between 2024-01-01 and 2024-01-15."
- Collaborative editing: "Show all edits made by User X to this record."
- AI-assisted recovery: "Suggest likely corrections based on this record’s history."
- Use Cases:
- Admin panels: "View and revert user-generated content (e.g., CMS pages, forum posts)."
- Financial systems: "Audit all changes to invoices or payments."
- Healthcare: "Track modifications to patient records with immutable snapshots."
- E-commerce: "Restore a cart or order to a previous state before fulfillment."
When to Consider This Package
Adopt if:
- Your Laravel app manages critical data where change history is non-negotiable (e.g., financial, legal, or healthcare domains).
- You need fine-grained control over versioning (e.g., diffs for specific fields, state transitions, or batch operations).
- Concurrency is a concern: Thread-safe locking prevents version sequence corruption during high-write scenarios.
- You require storage efficiency with configurable snapshot intervals (e.g., full snapshots every 10 versions, diffs in between).
- Your team lacks bandwidth to build/maintain a custom versioning system.
Look elsewhere if:
- You only need simple soft deletes or basic audit logs (use Laravel’s built-in
audit_log packages or observables).
- Your models are read-heavy with minimal updates (overhead of versioning may not justify benefits).
- You need offline-first or edge device support (this is server-side only).
- Your data is highly denormalized or uses complex relationships that break diff logic (e.g., polymorphic many-to-many).
- You’re using non-Eloquent models (e.g., raw query builder results or third-party ORMs).
Alternatives to evaluate:
- Laravel Audit Log: Lightweight, but lacks time-travel, diffs, or state transition tracking.
- Tymon/JWT-Auth + Custom Tables: More control, but requires significant upfront work.
- PostgreSQL Temporal Tables: Native DB-level versioning, but vendor-locked to PostgreSQL.
How to Pitch It (Stakeholders)
For Executives (1–2 Sentences)
"Laravel Rewind adds Git-like version control to our critical data models, enabling us to audit changes, undo mistakes, and comply with regulations without custom development. It’s like Ctrl+Z for our database, with built-in diffs, snapshots, and batch operations—saving us time and reducing risk in high-stakes workflows."
Business Impact:
- Mitigate risk: Recover from accidental data loss or fraudulent edits.
- Improve compliance: Automate audit trails for GDPR, HIPAA, or SOX requirements.
- Boost productivity: Let admins/users self-correct errors without dev intervention.
For Engineering (Technical Summary)
*"This package provides hybrid diff/snapshot versioning for Eloquent models with:
- Storage efficiency: Configurable snapshot intervals (e.g., full snapshots every 10 versions, diffs in between).
- Performance: Cache-based locking for thread safety; queued version creation for high-write models.
- Flexibility:
- Track state transitions (e.g., order status changes) separately from other attributes.
- Batch versioning: Group changes across multiple models into a single logical revision.
- Non-destructive restores: Create new versions from old states without breaking history.
- Queryability: Scopes to filter versions by user, date, event type, or state changes.
- Low overhead: Automatic pruning, amend mode for non-versioned changes (e.g., counters), and metadata attachment.
Trade-offs:
- Adds ~1–2ms per write (configurable via queueing).
- Storage grows linearly with version count (mitigated by snapshots and pruning).
- Requires
current_version column and a rewind_versions table.
Recommended for: Admin panels, financial systems, healthcare records, or any workflow where data provenance matters."*
For Developers (Implementation Notes)
*"To integrate:
- Add the
Rewindable trait to your models.
- Run
php artisan rewind:add-version to add the current_version column.
- Configure snapshot intervals, pruning rules, and queueing in
config/rewind.php.
- Use
Rewind::rewind(), Rewind::diff(), or state transition queries in your app logic.
Example Workflow:
// Track state transitions (e.g., order status)
class Order extends Model {
use Rewindable;
protected $rewindStateFields = ['status', 'payment_status'];
}
// Query transitions
$order->versions()
->whereStateTransition('status', 'pending', 'shipped')
->byUser(auth()->id())
->get();
// Undo a change
Rewind::rewind($order, 2); // Go back 2 versions
// or
Rewind::restore($order, 1); // Create a new version from v1’s state
DevOps:
- Schedule pruning with
php artisan rewind:prune --keep=50 --days=365.
- Monitor
rewind_version_lock_timeout events for concurrency issues.
- Extend
RewindVersion model for custom fields (e.g., ip_address or user_agent)."*