owen-it/laravel-auditing
Track and review changes to your Laravel Eloquent models with minimal setup. Laravel Auditing stores a history of model events and attribute diffs, helping detect anomalies and providing easy access to audit logs for display, reporting, and investigation.
Pros:
saved, deleted, updated). Aligns with Laravel’s observer/event-driven architecture.Auditable) to enable auditing with minimal code changes, reducing technical debt.Audit, UserResolver) enable modularity.Cons:
audits table (migration provided). Schema changes (e.g., adding updated_at in v4.1.0) may need backfilling.Auditable trait to models and configuring resolvers/drivers.retrieved events in v5.0.0).| Risk Area | Mitigation Strategy |
|---|---|
| Performance Overhead | Benchmark audit writes during peak loads. Use database indexing on auditable_id, event, and created_at. Consider asynchronous auditing (e.g., queue jobs) for high-write apps. |
| Schema Migration | Test migrations in a staging environment. Use backfill scripts for existing data. Monitor audits table growth. |
| Data Consistency | Validate audit data against source models periodically. Use checksums or hashes for critical fields. |
| Version Lock-in | Pin to a specific minor version (e.g., 14.x) to avoid breaking changes. Monitor Laravel compatibility. |
| Custom Resolver Bugs | Unit test resolvers (e.g., IpAddressResolver) in isolation. Use fallback resolvers for critical paths. |
| Audit Retention | Implement TTL-based pruning (e.g., Audit::where('created_at', '<=', now()->subYears(1))->delete()) or archive to cold storage. |
AttributeRedactor.)audits table size? Plan for archiving.| Phase | Tasks |
|---|---|
| Pre-Integration | 1. Audit Inventory: Identify models requiring auditing (prioritize high-risk/regulatory-sensitive ones). |
2. Version Lock: Pin Laravel and PHP versions to a supported laravel-auditing release (e.g., 14.x for Laravel 11–13). |
|
3. Schema Design: Review audits table structure. Plan for indexes (e.g., auditable_id, event, created_at) and partitioning if >1M records. |
|
| Pilot Phase | 4. Enable Auditing: Add use OwenIt\Auditing\Contracts\Auditable; and implements Auditable to a single model (e.g., User). |
5. Configure Resolvers: Set up UserResolver, IpAddressResolver, etc., in config/auditing.php. |
|
| 6. Test Edge Cases: Verify audits for soft deletes, mass updates, and relationship changes. | |
| Rollout | 7. Incremental Adoption: Enable auditing for 1–2 models at a time. Monitor performance. |
8. Data Migration: Backfill existing data for critical models (e.g., seed initial audits for created_at ranges). |
|
9. UI/Export: Build a Laravel Nova resource or API endpoint to query audits (e.g., /audits?model=User&event=updated). |
|
| Post-Launch | 10. Pruning Strategy: Implement a cron job to archive/prune old audits (e.g., keep 2 years of data). |
| 11. Alerting: Set up monitoring for failed audits (e.g., database errors) and anomalies (e.g., sudden audit volume spikes). |
creating, created, updating, updated, deleting, deleted, restoring, retrieved, and saved.exclude config or auditable() method to skip fields (e.g.,How can I help you explore Laravel packages today?