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

sonata-project/entity-audit-bundle

Doctrine 2 entity versioning for Symfony, inspired by Hibernate Envers. Tracks changes to audited entities and associations, storing revision history you can browse and compare for full audit trails.

View on GitHub
Deep Wiki
Context7

Audit for Doctrine Entities

Frequently asked questions about Entity Audit Bundle
Can I use Sonata EntityAuditBundle directly in Laravel, or is it only for Symfony?
While the bundle is designed for Symfony, its core library (simple-things/entity-audit) is framework-agnostic. You can integrate it into Laravel by bridging Doctrine ORM events with Eloquent using doctrine/dbal or custom event listeners. The README provides standalone installation instructions for non-Symfony projects.
How do I configure EntityAuditBundle to work with Laravel’s Eloquent models?
You’ll need to map Eloquent events (e.g., `saved`, `deleted`) to Doctrine listeners. Use doctrine/dbal to hook into Eloquent’s lifecycle and forward changes to the audit bundle’s subscribers. For example, dispatch a custom event in Eloquent’s observer that triggers the audit logic via a service container binding.
Does EntityAuditBundle support Laravel’s soft deletes (deleted_at) for auditing?
The bundle marks deletions as `revtype: DEL` in the audit log. If you use Laravel’s soft deletes, ensure your application treats these as logical deletions (not physical) and configure the bundle to ignore `deleted_at` timestamps or handle them via custom global_ignore_columns in your entity configuration.
Will this bundle slow down my Laravel application due to audit logging?
Yes, audit logging adds overhead since it writes to additional tables on every CRUD operation. To mitigate this, consider queueing audit logs (e.g., using Laravel Queues) or running schema updates asynchronously. Benchmark performance with your expected workload to assess the impact.
How do I query historical revisions of an Eloquent model in Laravel?
Wrap the bundle’s `AuditReader` methods in a facade or repository to abstract Doctrine-specific logic. For example, create a `Audit` facade that translates Eloquent model classes to Doctrine entities and uses `findRevisions()` or `find()` to fetch historical data. Example: `Audit::find(User::class, 1, 3)` for revision 3 of user ID 1.
Can I audit relationships (e.g., ManyToMany, OneToOne) between Eloquent models?
Yes, the bundle supports association versioning, but Laravel’s polymorphic or complex relationships may require custom handling. Configure `global_ignore_columns` to exclude non-auditable fields and test with relationships like `belongsToMany` to ensure changes are captured correctly in the audit tables.
What Laravel versions are compatible with Sonata EntityAuditBundle?
The bundle itself targets Symfony 8+, but Laravel 10+ should work with minor adjustments (e.g., Doctrine 2.13+). Test with a minimal setup first, as integration depends on doctrine/dbal compatibility. Laravel 9 may require additional bridging for event systems.
How do I generate the audit tables in Laravel migrations?
The bundle uses Doctrine’s `SchemaTool` to create audit tables (e.g., `*_audit`). Adapt this to Laravel by running the schema updates in a dedicated migration or using doctrine/dbal’s `SchemaManager`. Example: `SchemaManager::createSchema($schema)` where `$schema` includes the bundle’s audit tables.
Is there a way to exclude specific fields or models from auditing?
Yes, configure `global_ignore_columns` in your entity’s audit settings to exclude fields (e.g., `['password', 'api_token']`). To exclude entire models, omit them from the `audit` configuration or use a custom `AuditEntityListener` to filter entities dynamically.
What are the alternatives to Sonata EntityAuditBundle for Laravel?
For Laravel, consider `spatie/laravel-activitylog` (simpler, Eloquent-focused) or `owen-it/laravel-auditing` (supports soft deletes and async logging). If you need Hibernate Envers-like features, `baum/baum` (for CMS) or a custom solution using Doctrine listeners may be better. Evaluate based on your need for association tracking and compliance features.
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.
phalcon/cli-options-parser
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/privacy-filter-classifier
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata