Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Eloquent Versioned Laravel Package

sbarre/eloquent-versioned

Keep a full revision history for your Eloquent models: automatically store versions on save, browse past changes, and restore earlier states. Handy for audit trails, undo, and content workflows in Laravel apps.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install the package with Composer, then complete any Laravel 5.2-specific setup: register the service provider manually if package auto-discovery is not available, publish config/migrations, and run migrations.
  • Add the package’s versioning trait/interface to the Eloquent model you want to track. Check the README for the exact trait name and expected schema columns before wiring it into production models.
  • First day-to-day use case: render a model’s version history. From a version record, use getPreviousModel() and getNextModel() to build previous/next navigation on a version detail page.
  • Start by testing the flow on one low-risk model: create, update, load history, and traverse between adjacent versions. Confirm boundary behavior before building UI around it.

Implementation Patterns

  • Version creation: keep normal Eloquent create/update flows, but wrap writes that depend on generated model IDs in a database transaction. The 0.1.2 model_id fix reduces race risk, but transactions and sensible DB constraints still belong in application code.
  • Version browsing: load a model’s versions ordered by a stable key such as created_at plus id, then use getPreviousModel() / getNextModel() for detail-page navigation. These methods fit naturally into “older/newer version” links and audit/history screens.
  • Controller pattern: authorize access to both the source model and the version record, then pass current/previous/next versions to the view. Do not rely on route model binding alone if versions may reference soft-deleted or restricted records.
  • UI pattern: show version metadata, previous/next buttons, and a link back to the live model. Disable buttons when the traversal methods return null.
  • Query pattern: scope history queries by the configured model type/id columns and paginate large histories. Eager-load relationships needed on version detail pages to avoid N+1 queries.
  • Laravel 5.2 pattern: treat this release as the compatibility baseline. Test middleware, route model binding, and service-provider registration on 5.2 specifically; do not assume the same setup works on modern Laravel without checking constraints.
  • Integration tip: publish and review the package config/migrations rather than editing vendor files. If the package supports configurable table/model columns, set those before running migrations in existing apps.

Gotchas and Tips

  • This is an early 0.1.x package. Pin the version in composer.json and review the README/changelog before upgrading; APIs around version traversal and model association may still evolve.
  • getPreviousModel() and getNextModel() will likely return null at the boundaries of a version list. Handle that explicitly in controllers and views.
  • The improved model_id determination helps with race conditions, but concurrent writes can still create ordering ambiguity. Use transactions, stable ordering, and database constraints where correctness matters.
  • Do not order solely by created_at; timestamps can collide. Use a deterministic secondary sort such as id.
  • Laravel 5.2 compatibility means older framework conventions may apply: manual provider registration, older package-discovery behavior, and different testing/setup expectations. Verify before mixing this package into a newer Laravel codebase.
  • Version records can expose historical values that are no longer public. Add authorization and field filtering at the application layer.
  • Test both traversal directions and edge cases: first version, last version, deleted model, and multiple rapid updates. Feature tests should assert that previous/next links never point to a version from another model.
  • Treat published config and migrations as extension points. If the package defaults do not fit existing table naming or tenancy rules, adjust them early rather than patching vendor code.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource