- Does proai/eloquent-versioning work with Laravel 8/9/10 or only Laravel 5.x?
- This package is designed for Laravel 5.x and may not work out-of-the-box with newer versions (8/9/10) due to Eloquent API changes, PHP 8.x features, or dependency injection shifts. You’d need to test compatibility or fork the package for modern Laravel.
- How do I set up versioning for specific model attributes?
- Define the `$versioned` array in your model class (e.g., `['email', 'city']`) and use the `Versionable` trait. The package automatically stores changes in a dedicated version table (e.g., `users_version`) during updates.
- Can I version soft deletes and timestamps with this package?
- Yes, include `deleted_at` and `updated_at` in your `$versioned` array. The `SoftDeletes` trait ensures these changes are tracked in the version table alongside other attributes.
- What’s the performance impact of querying historical versions?
- Version queries involve joins with the versions table, which can slow down high-frequency reads. Optimize with indexes on `versioned_at`, `model_id`, or cache frequent queries (e.g., Redis) to mitigate performance hits.
- Is there a way to roll back a model to a previous version?
- The package doesn’t natively support programmatic rollbacks. You’d need to manually restore data from the versions table or build a custom method to update the model with historical values.
- How do I handle foreign key constraints if versioned records are soft-deleted?
- Foreign keys in the versions table should reference the main model’s `id`, not `deleted_at`. If the parent model is soft-deleted, version records remain intact unless explicitly purged, avoiding orphans.
- Are there alternatives to this package for Laravel 8+?
- For modern Laravel, consider `spatie/laravel-activitylog` (event-based) or `laravel-model-versions` (active maintenance). These packages address compatibility gaps and offer additional features like diffing or bulk operations.
- How do I migrate an existing Laravel 5.x project to use this package?
- Add the `latest_version` column to your main table and create a version table (e.g., `users_version`). Use the `Versionable` trait in your model and specify `$versioned` attributes. Run migrations before enabling versioning.
- Does this package support PHP 8.x or only PHP 5.6+?
- The package requires PHP 5.6+ (for Laravel 5.x) but may fail in PHP 8.x due to deprecated functions (e.g., `array_column`) or named arguments. Test thoroughly or patch the code for PHP 8.x compatibility.
- Can I version multiple models with different schemas in one project?
- Yes, apply the `Versionable` trait to each model and define a unique version table per model (e.g., `users_version`, `products_version`). The package dynamically handles schema differences for each model.