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.
Pros:
*_audit) during migrations, reducing manual SQL overhead. Compatible with Laravel’s migration system if configured via Doctrine extensions (e.g., doctrine/dbal).find), revision lists (findRevisions), and diffs (compare), which can be adapted for Laravel’s query builder or repositories.simple-things/entity-audit) is framework-agnostic and can be integrated into Laravel via standalone usage (see Installation (Standalone)).Cons:
doctrine/dbal + custom listeners).High-Level Path:
doctrine/dbal to hook into Laravel’s Eloquent lifecycle (e.g., saving, deleted) and forward events to the audit bundle’s listeners.SchemaTool to work with Laravel migrations (e.g., via doctrine/dbal schema updates).AuditReader methods for Eloquent compatibility (e.g., Audit::find(Model::class, $id, $revision)).username_callable to integrate with Laravel’s auth system (e.g., Auth::user()->name).Key Challenges:
ModelObserver, Events::dispatch) differ from Doctrine’s event system. Requires a translation layer.global_ignore_columns).| Risk Area | Severity | Mitigation |
|---|---|---|
| Doctrine-Eloquent Integration | High | Use doctrine/dbal as a bridge; test with a minimal entity first. |
| Schema Migration Conflicts | Medium | Run bundle’s schema updates in a dedicated migration or use --dry-run. |
| Performance Impact | Medium | Benchmark write operations; consider async logging (e.g., queue-based audits). |
| Query Complexity | Low | Abstract AuditReader behind a simple facade to hide Doctrine-specific logic. |
| Association Bugs | Medium | Test with complex relationships (e.g., ManyToMany, OneToOne). |
| Laravel Version Support | Low | Bundle supports Symfony 8+; Laravel 10+ should work with minor adjustments. |
Is audit granularity sufficient?
rev + revtype) meet requirements, or are entity-level timestamps needed?How to handle Laravel’s unique features?
revtype: DEL. Will this conflict with Laravel’s deleted_at?created_at/updated_at are ignored by default. Should these be audited separately?Async Logging Needs
Query Performance
findRevisions) optimized (e.g., indexed rev columns)?Testing Strategy
Rollback Support
Core Compatibility:
doctrine/dbal v4).doctrine/dbal + custom listeners to mirror Eloquent events.Model class to dispatch Doctrine events.Dependencies:
doctrine/dbal (≥4.0) for schema management.simple-things/entity-audit (≥2.0) for core logic.doctrine/orm (if using full Doctrine ORM; overkill for Laravel).laravel/framework (≥10.0) for event/queue integration.Conflicts:
SchemaTool may conflict with Laravel’s migrations. Mitigation:
--dry-run to preview SQL changes.revtype: DEL. Ensure this aligns with Laravel’s SoftDeletes trait.Phase 1: Proof of Concept (1–2 weeks)
User) to validate integration.doctrine/dbal and simple-things/entity-audit.AuditServiceProvider to bootstrap the bundle’s listeners.entity_audit.yaml (or PHP equivalent) for the test entity.php artisan doctrine:schema:update --dump-sql to preview audit tables.AuditReader (e.g., Audit::find()).Phase 2: Full Integration (2–4 weeks)
Model::saved() → preFlush).UserAuditRepository).username_callable to use Laravel’s Auth system.rev, entity_id).Phase 3: Optimization (Ongoing)
| Laravel Feature | Compatibility | Workaround |
|---|---|---|
| Eloquent ORM | Medium (requires event bridge) | Use doctrine/dbal to listen to Eloquent events. |
| Soft Deletes | Low (conflict with revtype: DEL) |
Extend bundle to handle deleted_at or disable auditing for soft-deleted models. |
Timestamps (created_at) |
High (ignored |
How can I help you explore Laravel packages today?