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

Laravel Auditing Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Seamless Laravel Integration: Designed natively for Laravel, leveraging Eloquent models and events (e.g., saved, deleted, updated). Aligns with Laravel’s observer/event-driven architecture.
    • Minimal Boilerplate: Uses traits (Auditable) to enable auditing with minimal code changes, reducing technical debt.
    • Extensible: Supports custom resolvers (e.g., IP, user agent, URL), drivers (database, logging), and event hooks. Contracts (e.g., Audit, UserResolver) enable modularity.
    • Compliance-Focused: Tracks changes for regulatory compliance (GDPR, SOX) or operational audits (e.g., tracking sensitive data modifications).
    • Performance Optimizations: Only audits modified attributes (v4.0.0+) and supports dynamic exclusion (v13.0.0+).
  • Cons:

    • Database Dependency: Default driver stores audits in a separate table, adding write overhead during model operations. May impact performance for high-frequency writes.
    • Monolithic Audits Table: Schema grows with model attributes, requiring careful migration planning for large-scale apps.
    • Event Coupling: Auditing triggers on Eloquent events, which could mask bugs if events are misconfigured (e.g., duplicate audits).
    • No Native Soft Deletes for Audits: Requires manual handling of audit retention (e.g., pruning old records).

Integration Feasibility

  • Laravel Version Compatibility:
    • Active Support: Laravel 11.x–13.x (PHP 8.2+). If using Laravel 10.x or below, requires downgrading to v13.x or earlier (EOL risks).
    • Lumen Support: Confirmed in v8.0.2, but may need testing for edge cases.
  • Database Requirements:
    • Supports MySQL, PostgreSQL, SQLite, SQL Server (via Eloquent). No native NoSQL support.
    • Requires a dedicated audits table (migration provided). Schema changes (e.g., adding updated_at in v4.1.0) may need backfilling.
  • Existing Code Impact:
    • Low Risk: Only requires adding the Auditable trait to models and configuring resolvers/drivers.
    • High Risk: If models use custom attribute casting/mutators, auditing may not capture expected values (fixed in v4.0.0 but test thoroughly).
    • Event Conflicts: Ensure no existing event listeners override auditing logic (e.g., retrieved events in v5.0.0).

Technical Risk

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.

Key Questions for Stakeholders

  1. Compliance Requirements:
    • Are audits required for legal/regulatory purposes (e.g., GDPR Article 30)? If so, validate retention policies.
    • Do audits need to be tamper-proof (e.g., write-only logs, digital signatures)?
  2. Performance SLAs:
    • What is the acceptable latency for model operations with auditing enabled?
    • Is asynchronous auditing viable (e.g., via Laravel queues)?
  3. Data Sensitivity:
    • Which model attributes are PII/sensitive and must be redacted in audits? (Use AttributeRedactor.)
    • Should audits include full attribute dumps or only deltas?
  4. Operational Trade-offs:
    • What is the maximum acceptable audits table size? Plan for archiving.
    • Should audits be searchable (e.g., via Laravel Scout) or exported periodically?
  5. Monitoring:
    • How will audit failures (e.g., database errors) be alerted? (Integrate with Laravel Horizon or Sentry.)
    • Are audit anomalies (e.g., sudden spikes) to be monitored?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Core Fit: Optimized for Laravel’s Eloquent ORM, events, and service container. Works alongside Laravel Nova, Laravel Forge, and Laravel Vapor.
    • Testing: Compatible with PestPHP, PHPUnit, and Laravel Dusk for audit validation.
    • APIs: Seamless integration with Laravel Sanctum (for user tracking) and Laravel Echo (real-time audit notifications).
  • Third-Party Extensions:
    • Database: Works with Doctrine DBAL, Elasticsearch, or MongoDB via custom drivers.
    • Auth: Integrates with Laravel Breeze, Jetstream, or Fortify for user resolution.
    • Logging: Can log audits to Monolog or Sentry as an alternative to the database driver.
  • Non-Laravel Considerations:
    • PHP-FPM: Auditing adds overhead; monitor PHP process memory usage.
    • Caching: Audit queries may bypass cache; use database query caching or Redis for frequent reads.

Migration Path

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).

Compatibility

  • Laravel Features:
    • Eloquent Events: Works with creating, created, updating, updated, deleting, deleted, restoring, retrieved, and saved.
    • Model Observers: Auditing can coexist with observers but may conflict if both modify the same attributes.
    • Scopes/Accessors: Audited attributes must be public or accessible via getters/setters.
  • Customizations:
    • Excluded Attributes: Use exclude config or auditable() method to skip fields (e.g.,
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai