versionable

Laravel model versioning made easy: track every Eloquent model change and revert to previous versions.

Library
Composer
v4.4.8
787stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
48/100Fair
Development Activity8
Maintenance20
Community76
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture72
Code Quality74
Innovation62
Learning Curve90

mpociot/versionable is a Laravel package that adds automatic version history to Eloquent models. By adding a single trait to a model, every update stores a snapshot of the previous attributes so you can review the full change history and revert to any earlier state.

It handles the common needs of auditable data: excluding attributes from versioning, capturing the user responsible for a change, restoring soft-deleted or overwritten records, and seeding an initial version for existing data, all with minimal configuration.

What You Get

  • A VersionableTrait that enables automatic version tracking on any Eloquent model
  • A versions table and migration storing snapshots via a polymorphic relation
  • previousVersion() and revert() helpers to roll a model back to an earlier state
  • Options to exclude specific attributes and limit how many versions are kept
  • Helpers to seed initial versions for pre-existing data (createInitialVersion, initializeVersions)

Common Use Cases

  • Maintaining an audit trail of changes to important domain models
  • Letting users undo edits by reverting to a previous version of a record
  • Recording who made each change for compliance or accountability
  • Backfilling version history when adding versioning to an existing app

Under The Hood

Architecture - The package centers on Mpociot\Versionable\VersionableTrait, which hooks Eloquent model events so that updates persist the model’s prior attributes into a Version model. Version stores the versionable type/id polymorphically and can reconstruct the original model via getModel(), while revert() writes those attributes back. A ServiceProvider registers config and migrations.

Tech Stack - PHP >=7.1 and illuminate/support spanning Laravel 5.3 through 13. It ships a migration for the versions table and a config file. Dev tooling uses PHPUnit, Mockery, and Orchestra Testbench for package testing against Laravel.

Code Quality - The code is small and focused, driven by a trait plus a Version model and provider. It includes a tests directory run under PHPUnit with Testbench and historically reported coverage via Codecov and Scrutinizer, indicating attention to correctness across many Laravel versions.

API Design - The developer experience is deliberately minimal: add one trait and versioning just works. Reverting and inspecting history read naturally (previousVersion()->revert(), Version::find(id)->getModel()), and configuration for exclusions and limits stays out of the way until needed.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search