visualbuilder/versionable
Laravel model versioning with polymorphic user support. Track and store a history of changes across multiple user types/guards, keep a set number of versions, whitelist/blacklist attributes, record only diffs, and easily revert models to any saved version.
Admin, Client, Vendor users) by leveraging Laravel’s morphTo without manual foreign key management. Critical for SaaS/multi-tenant apps.Post but not User). Low intrusion risk.jfcherng/php-diff adds visual change tracking (HTML/JSON/text), justifying use in compliance-heavy domains (e.g., healthcare, finance).saving/updating events, which may conflict with other event-based packages (e.g., spatie/laravel-activitylog).versions table with polymorphic user_id/user_type. Migration is automated but requires downtime if applied to production.saving/updating events (e.g., spatie/laravel-activitylog) may interfere. Mitigate via event priority or conditional hooks.auth()->user() returns a model with morphMany support. Custom auth? Verify compatibility.DIFF (default) vs. SNAPSHOT tradeoffs (storage vs. fidelity).\Visualbuilder\Versionable\Version for schema tweaks.User extends a custom base class)?removeAllVersions) could be slow for millions of records.diff() operations impact response times in admin panels?DIFF strategy, storage scales with changes, not snapshots. Estimate growth for high-frequency updates.$versionable->lockForUpdate()).spatie/laravel-activitylog (more features, higher maintenance) or overtrue/laravel-versionable (original, no polymorphic users).Versionable trait. Non-Eloquent models (e.g., API resources) are unsupported.auth()->user() returns a model with morphMany support.versions.user_id + versions.user_type).saving/updating).composer require visualbuilder/versionable
php artisan vendor:publish --provider="Visualbuilder\Versionable\ServiceProvider"
php artisan migrate
use Visualbuilder\Versionable\Versionable; to target models.$versionable (whitelist) or $dontVersionable (blacklist).class Post extends Model {
use Versionable;
protected $versionable = ['title', 'content'];
protected $versionStrategy = VersionStrategy::DIFF; // Optional
}
Admin vs. Client).mansoorkhan96/filament-versionable for UI integration.spatie/laravel-activitylog (duplicate versioning).SoftDeletes trait (versions are soft-deleted too).\Visualbuilder\Versionable\Version for custom fields (e.g., ip_address).bootVersionable() to add pre/post hooks.BlogPost).Customer, Product) after validation.versions).jfcherng/php-diff (external). Pin versions to avoid breaking changes.dd($version->user) to inspect relationships.diff() (e.g., non-serializable objects).auth()->user() must return a model. Use optional(auth()->user()) to avoid errors.$versionable includes all mutable fields.removeAllVersions() could lock tables. Use chunking:
$post->versions()->cursor()->each(function ($version) {
$version->delete();
});
$diff = $post->getVersion(1)->diff($post->getVersion(2)); // Heavy!
versions(model_id, created_at) for query performance:
Schema::table('versions', function (Blueprint $table) {
$table->index(['model_id', 'created_at']);
});
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Polymorphic User Resolution | Version records user_id/type incorrectly. |
Validate `auth |
How can I help you explore Laravel packages today?