Weave Code
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
Entity Audit Bundle

Entity Audit Bundle Laravel Package

simplethings/entity-audit-bundle

Doctrine 2 auditing/versioning bundle inspired by Hibernate Envers. Tracks entity changes and associations over time, stores revisions, and lets you inspect historical states for debugging, compliance, and change history in Symfony/Doctrine apps.

View on GitHub
Deep Wiki
Context7

Audit for Doctrine Entities

Frequently asked questions about Entity Audit Bundle
Can I use EntityAuditBundle in Laravel without Symfony, or is it strictly Symfony-only?
While the bundle is Symfony-centric, its core logic (Doctrine events + mirror tables) works in Laravel if you use Doctrine ORM via packages like `doctrine/dbal` or `laravel-doctrine/orm`. Eloquent projects would need a custom wrapper to intercept model events and delegate to the bundle’s `AuditManager`. The bundle itself doesn’t provide Laravel-specific service providers or Artisan commands.
How do I install EntityAuditBundle in Laravel with Doctrine ORM?
First, install via Composer: `composer require sonata-project/entity-audit-bundle`. Then configure it in your `config/packages/doctrine.yaml` (or equivalent) to register the bundle’s services. Replace Symfony’s `EntityManager` with Laravel’s Doctrine instance in the bundle’s configuration. Audit tables must be manually added to Laravel migrations or via a post-install script, as the bundle doesn’t auto-generate them for Laravel.
Will EntityAuditBundle work with Laravel’s Eloquent ORM?
No, the bundle requires Doctrine ORM and won’t work natively with Eloquent. To use it with Eloquent, you’d need to create a custom wrapper that listens to Eloquent model events (e.g., `saved`, `deleted`) and manually triggers the bundle’s `AuditManager` for each change. This adds complexity but is technically feasible for projects needing deep audit trails.
How does EntityAuditBundle handle database migrations in Laravel?
Audit tables (e.g., `*_audit`) are not auto-generated by the bundle in Laravel, so you must manually add them to your migrations using raw SQL or Laravel’s `Schema` builder. The bundle’s `SchemaTool` (used in Symfony) won’t work out-of-the-box. For existing projects, you may need to write a custom migration class or use a post-install script to create the audit tables with the correct schema.
What Laravel versions and Doctrine ORM versions does EntityAuditBundle support?
The bundle itself doesn’t enforce Laravel version constraints, but it requires Doctrine ORM 2.5+. For Laravel compatibility, ensure you’re using a Doctrine bridge package (e.g., `laravel-doctrine/orm`) that supports your Laravel version (8.x, 9.x, or 10.x). Check the bundle’s [Doctrine compatibility table](https://github.com/sonata-project/EntityAuditBundle#requirements) for specific ORM version requirements.
Does EntityAuditBundle support soft deletes in Laravel?
Yes, but you’ll need to configure it manually. The bundle tracks `DEL` revisions for soft-deleted entities, but conflicts can arise if Laravel’s `SoftDeletes` trait is used. Explicitly ignore the `deleted_at` column in the bundle’s `global_ignore_columns` configuration to prevent duplicate audit entries. Test thoroughly with your soft-delete logic to ensure consistency.
How can I query historical data or diffs between revisions in Laravel?
Use the bundle’s `AuditReader` service to fetch historical states, revisions, or diffs. For example, `findRevisions()` retrieves all revisions for an entity, while `findRevision()` gets a specific snapshot. In Laravel, inject the `AuditReader` into a service or controller and call its methods. For read-heavy applications, consider indexing the `rev` and `timestamp` columns in your audit tables to improve query performance.
Are there performance concerns with EntityAuditBundle in high-write Laravel apps?
Yes, the bundle adds write overhead by duplicating entity changes to audit tables (1→2 DB operations per update). In high-write systems, this can slow down performance. Mitigate by indexing audit table columns (e.g., `rev`, `timestamp`) and testing with benchmarks. For read-heavy audit queries, consider caching `AuditReader` results or implementing a custom query layer.
How do I secure audit logs to show the current user’s name in Laravel?
The bundle supports tracking usernames via the `username` field in audit tables, but you’ll need to configure it manually. In Laravel, override the bundle’s `AuditManager` or use a custom event subscriber to set the username dynamically (e.g., `Auth::user()->name`). Ensure your authentication system is properly integrated to avoid null or generic usernames in audit logs.
What alternatives exist for auditing in Laravel if EntityAuditBundle isn’t a good fit?
For Laravel projects, consider `spatie/laravel-activitylog` (Eloquent-focused, simpler setup) or `owen-it/laravel-auditing` (supports Eloquent and Doctrine). If you need Doctrine ORM integration without Symfony, `Gedmo/DoctrineExtensions` (with its `Timestampable` and `Loggable` behaviors) is another option. For custom solutions, you could build a lightweight audit system using Eloquent observers or Doctrine event listeners tailored to your needs.
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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views