- How does Laravel Rewind handle storage efficiency for versioned Eloquent models?
- Rewind uses a hybrid storage model combining diffs (for incremental changes) and snapshots (full copies at configurable intervals). This balances storage savings with fast reconstruction. You can adjust the `snapshot_interval` in config to optimize for your workload—frequent snapshots reduce diff complexity but increase storage.
- Can I use Laravel Rewind with Laravel 9 or older versions?
- No, Laravel Rewind requires Laravel 10+ due to its dependency on PHP 8.1+ features and Eloquent’s updated query builder. The package follows Laravel’s latest conventions, so downgrading isn’t supported. Check the [GitHub releases](https://github.com/avocet-shores/laravel-rewind/releases) for version-specific notes.
- What databases does Laravel Rewind support, and are there any limitations?
- Rewind supports MySQL, PostgreSQL, and SQLite out of the box. It relies on JSON fields for storing diffs/snapshots, so ensure your database supports JSON data types. No vendor-specific queries are used, but complex JSON operations (e.g., large nested attributes) may impact performance. Test with your database’s JSON handling first.
- How do I enable versioning for an existing Eloquent model without losing data?
- Add the `Rewindable` trait to your model and run the migrations to add the `current_version` column. For existing data, call `initVersion()` on each model instance or seed `rewind_versions` manually. Rewind preserves all future changes automatically—no data loss occurs during migration.
- What happens if two users edit the same model concurrently? Will versions conflict?
- Rewind uses cache-based locking (via Laravel’s cache system) to prevent race conditions. Concurrent writes are thread-safe, but extreme contention (e.g., 10K+ writes/sec) may cause lock timeouts. Monitor `RewindVersionLockTimeout` events and consider Redis/Memcached for high-traffic apps. Locks are short-lived and release automatically.
- Can I query or restore a model to a specific point in time, like `WHERE created_at < '2023-01-01'`?
- Yes! Use `Rewind::goTo($model, $versionNumber)` to jump to any version or `Rewind::restore($model, $versionNumber)` to create a new version from an old state. For time-based queries, combine with Eloquent’s query builder: `$model->where('created_at', '<', $date)->withRewindHistory()->get()`.
- How does batch versioning work for related models (e.g., orders and order items)?
- Batch versioning groups changes across multiple models into a single logical revision using transactions. For example, updating an `Order` and its `OrderItem`s triggers one batch revision. This ensures atomicity—either all models are versioned or none. Use `Rewind::batch()` in your service layer to wrap related updates.
- What’s the impact of Rewind on production performance, especially with queued writes?
- Rewind offloads version creation to queues by default, reducing latency. However, queued jobs may backlog under heavy load. Monitor queue failures and adjust `queue` settings in config. For high-traffic apps, test with realistic data volumes and consider increasing `snapshot_interval` to reduce diff complexity.
- How do I prune old versions to manage database size, and is it safe?
- Use the `Rewind::prune()` command with options like `--keep=30 --days=90` to retain versions. Pruning is non-destructive—it only removes versions from the `rewind_versions` table while preserving the audit trail. Always back up your database before pruning and test in staging first.
- Are there alternatives to Laravel Rewind for versioning Eloquent models?
- Alternatives include `spatie/laravel-activitylog` (for simpler audit logs), `laravel-model-versions` (snapshot-only), or custom solutions with `laravel-audit` + `laravel-archivist`. Rewind stands out with its hybrid diff/snapshot engine, thread safety, and batch versioning for related models—ideal for complex workflows like orders or tickets.