- How do I enable versioning for an Eloquent model in Laravel?
- Use the `Rewindable` trait on your model and add a `current_version` column to your database table. Run the `rewind:install` Artisan command to create the versions table. Versioning is automatic for all updates unless explicitly skipped.
- What’s the difference between snapshots and diffs in Laravel Rewind?
- Rewind uses a hybrid approach: full snapshots are taken at configurable intervals (e.g., every 10 versions), while intermediate changes are stored as diffs. This balances storage efficiency with fast reconstruction—snapshots ensure quick rollbacks, while diffs minimize space usage.
- Does Laravel Rewind work with Laravel 9/10/11, or only newer versions?
- The package officially supports Laravel 9+. For Laravel 8 or older, you may need to manually adjust dependencies or use polyfills. Always check the [GitHub releases](https://github.com/avocet-shores/laravel-rewind/releases) for version-specific notes.
- How do I handle high-write volumes (e.g., 1000+ updates/sec) without performance issues?
- Enable queued versioning via `listener_should_queue` in your model’s `rewindable()` method. For non-critical updates, use `amendCurrentVersion()` to avoid creating new versions. Monitor queue backlogs and adjust worker capacity accordingly.
- Can I restore a model to a previous version without affecting its current state?
- Yes, use `Rewind::restore($model, $version)` to create a new version based on an older state while preserving the current version. This is non-destructive and maintains the full audit trail.
- How does thread safety work in Laravel Rewind? Will concurrent writes corrupt version history?
- Rewind uses cache-based locking to ensure thread safety. Each write acquires a lock to prevent version sequence breaks. Misconfigured lock timeouts (`on_lock_timeout`) could cause issues, but defaults log failures. For production, test with your expected concurrency levels.
- What’s the best way to manage storage growth for long-lived models (e.g., user accounts)?
- Use the `rewind:prune` Artisan command to automatically remove old versions. Configure retention policies via `snapshot_interval` and `keep` settings in your model. Schedule pruning jobs (e.g., daily) and monitor storage growth with database metrics.
- Does Laravel Rewind support custom metadata or events for version changes?
- Yes, extend the `RewindVersion` model to add custom fields. Use event hooks like `RewindVersionCreated` to trigger notifications, logs, or side effects. The package provides flexibility for integrating with your existing workflows.
- How do I query or diff between two versions of a model?
- Use `Rewind::diff($model, $version1, $version2)` to compare changes between versions. For querying historical states, use `Rewind::goTo($model, $version)` to load a model at a specific point in time, then inspect its attributes.
- Are there alternatives to Laravel Rewind for versioning Eloquent models?
- Alternatives include `spatie/laravel-activitylog` (for simpler audit logs) or `laravel-model-versions` (full snapshots). Rewind’s hybrid diff/snapshot approach is unique for balancing speed and storage, making it ideal for high-write applications needing fast rollbacks and compliance.