- How do I start auditing a Laravel Eloquent model with this package?
- Add the `Auditable` trait to your model class. The package automatically captures create, update, delete, and restore events. Run the provided migration to create the `audits` table, and you’re ready to track changes without extra code.
- Does this package support Laravel 10.x or older versions?
- No, the package officially supports Laravel 11.x–13.x (PHP 8.2+). For Laravel 10.x, downgrade to version 13.x of the package, but check the changelog for compatibility notes, as some features may differ.
- Can I exclude sensitive fields from being audited?
- Yes, use the `auditExclude` config option in `config/auditing.php` to specify fields that should never be logged. Alternatively, override the `getAuditExclude()` method in your model to dynamically control exclusions.
- How does performance impact scale with high-write applications?
- Each audit event triggers a database write, which can slow down high-throughput systems. Mitigate this by auditing only critical models, using `shouldAudit()` to filter events, or implementing a custom queue listener for batch processing.
- Is there a way to customize who or what triggers an audit log entry?
- Yes, implement custom `UserResolver` or `AttributeResolver` interfaces to dynamically set audit metadata like user IDs, IP addresses, or URLs. The package provides built-in resolvers for common use cases.
- Can I store audit logs in Redis or Elasticsearch instead of the database?
- Yes, the package supports custom audit drivers via the `AuditDriver` contract. You can create a driver for Redis, Elasticsearch, or other storage backends to optimize for search or analytics.
- How do I retrieve and display audit history for a model?
- Use the `audits()` method on your model instance to fetch a collection of audit records. Each record includes old/new values, timestamps, and metadata. Paginate results for large datasets with `audits()->paginate(10)`.
- What happens if I upgrade from an older version of this package?
- Check the changelog for breaking changes, especially in major versions (e.g., v8.0.0 removed `audit.redact`). Some updates, like adding `updated_at` to the audits table in v4.1.0, may require manual migration adjustments.
- Does this package work with Laravel Lumen?
- Yes, the package is tested and compatible with Lumen. The same installation and configuration steps apply, as Lumen shares Laravel’s Eloquent and event systems.
- Are there alternatives to this package for Laravel model auditing?
- Yes, alternatives include `spatie/laravel-activitylog` (feature-rich but heavier) and `laravel-audit-log` (simpler but less flexible). Choose based on your needs: this package excels in minimal setup and extensibility for Laravel-specific use cases.