Download the PHP package visualbuilder/versionable without Composer
On this page you can find all versions of the php package visualbuilder/versionable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download visualbuilder/versionable
More information about visualbuilder/versionable
Files in visualbuilder/versionable
Package versionable
Short Description Make Laravel model versionable with polymorphic user support (Fork of overtrue/laravel-versionable).
License MIT
Informations about the package versionable
Laravel Versionable (Polymorphic User Fork)
Fork of overtrue/laravel-versionable with polymorphic user support
This fork extends the original package to support polymorphic user relationships, allowing you to track versions created by different user model types (e.g., Admin, Associate, EndUser, etc.) in applications with multiple authentication guards.
It's a minimalist way to make your model support version history, and it's very simple to revert to the specified version.
What's Different in This Fork?
This fork replaces the single-user foreign key relationship with a polymorphic relationship, enabling:
- Support for multiple user model types (Admin, Associate, OrganisationUser, etc.)
- Automatic tracking of which user type created each version
- Compatibility with applications using multiple authentication guards
- No configuration needed - uses
auth()->user()to automatically detect the authenticated user
Key Changes:
- Migration: Uses
morphs('user')instead ofunsignedBigInteger('user_id') - Version Model: Uses
morphTo()for the user relationship instead ofbelongsTo() - Configuration: Removed
user_modelanduser_foreign_keyconfig options (no longer needed) - Versionable Trait: New
getVersionUser()method returns the authenticated user model
Requirement
- PHP >= 8.1.0
- laravel/framework >= 9.0
Features
- Keep the specified number of versions.
- Whitelist and blacklist for versionable attributes.
- Easily revert to the specified version.
- Record only changed attributes.
- Easy to customize.
Installing
Run:-
First, publish the config file and migrations:
Then run this command to create a database migration:
Usage
Add Visualbuilder\Versionable\Versionable trait to the model and set versionable attributes:
Versions will be created on the versionable model saved.
Polymorphic user example
Once you attach the trait to a versionable model, versions automatically store the currently authenticated user.
You can repeat the same pattern for any additional authenticatable model that should appear as a version author.
Get versions
Revert
Revert a model instance to the specified version:
Revert without saving
Remove versions
Restore deleted version by id
Temporarily disable versioning
Custom Version Store strategy
You can set the following different version policies through property protected $versionStrategy:
Visualbuilder\Versionable\VersionStrategy::DIFF- Version content will only contain changed attributes (default strategy).Visualbuilder\Versionable\VersionStrategy::SNAPSHOT- Version content will contain all versionable attribute values.
Show diff between the two versions
$diff is a object Visualbuilder\Versionable\Diff, it based
on jfcherng/php-diff.
You can render the diff to many formats, and all formats result will be like follows:
toArray()
Other formats
Note
$differOptionsand$renderOptionsare optional, you can set them following the README of jfcherng/php-diff.$stripTagsallows you to remove HTML tags from the Diff, helpful when you don't want to show tags.
Using custom version model
You can define $versionModel in a model, that used this trait to change the model(table) for versions
Note
Model MUST extend class
\Visualbuilder\Versionable\Version;
Update the model attribute $versionModel:
Integrations
- mansoorkhan96/filament-versionable Effortlessly manage revisions of your Eloquent models in Filament.
Credits
This package is a fork of overtrue/laravel-versionable.
All credit for the original implementation goes to @overtrue. This fork only adds polymorphic user support.
License
MIT
All versions of versionable with dependencies
laravel/framework Version ^9.0|^10.0|^11.0|^12.0|^13.0
jfcherng/php-diff Version ^6.11
doctrine/dbal Version ^3.8|^4.0