ss-ipg/laravel-auditable
Attribute-based audit logging for Laravel Eloquent models. Add #[Auditable] to track create/update/delete/soft delete/restore events with old/new values, column include/exclude/redact, per-model event filters, JSON formatting, and extensible context providers.
creating, updating, deleting), ensuring minimal performance overhead (only active during model operations).soft_deleted and deleted events, critical for compliance-heavy applications (e.g., healthcare, finance).config/logging.php).AUDITABLE_ENABLED=true).
Migration path: Low-risk for greenfield projects; brownfield projects may need event listener refactoring if existing audit logic relies on observers/events.storage/logs/audit.log). No additional tables required, reducing deployment complexity.Model::update([...])) do not trigger audits, requiring developer discipline to use model instances for critical operations. Mitigation: Document this in team guidelines or enforce via custom validation.Audit::fake() simplifies unit tests but may require adjustments to existing test suites if they mock events directly.AuditContextProvider.hasMany models)? This is out-of-scope; may need custom event listeners.single, daily, syslog, or third-party like Monolog). Recommended: Use daily with rotation for compliance.Audit::fake() integrates with Laravel’s testing helpers (e.g., assertLogged), reducing test maintenance overhead.| Current State | Migration Steps | Risks/Mitigations |
|---|---|---|
| No auditing | 1. Add #[Auditable] to critical models. 2. Configure log channel. 3. Enable via .env. |
None. |
| Custom observers/events | 1. Replace observers with attributes. 2. Update tests to use Audit::fake(). 3. Remove obsolete event listeners. |
Breakage: Ensure all audit logic is migrated (e.g., custom context). Use feature flags for gradual rollout. |
| Third-party audit packages | 1. Compare feature parity (e.g., column filtering, soft deletes). 2. Pilot with non-critical models. 3. Phase out old package. | Data loss: Validate log formats match compliance requirements. |
| Database-triggered audits | 1. Replicate audit logic in PHP (e.g., triggers → attributes). 2. Compare performance. 3. Deprecate triggers if PHP-based audits are sufficient. | Performance: Database triggers may outperform PHP for high-volume systems. Benchmark both approaches. |
SoftDeletes, Timestamps).updated_at matches audit timestamps).user_id from job payload). For async operations, ensure jobs include necessary context (e.g., auth()->setUser($user)).User, Setting).Payment, PatientRecord).Session, Log) unless critical.Audit::fake() to verify model operations.storage/logs/audit.log)..env in staging first.audit.log file size, disk I/O).columns, exclude) are co-located with models, reducing misconfiguration risk.AUDITABLE_ENABLED=true and log channel exists.Model::update()).tideways/xhprof to profile audit overhead.Audit::logged() for runtime inspection.log:tail for real-time log monitoring.config(['auditable.enabled' => false])).How can I help you explore Laravel packages today?