- How do I start auditing Eloquent models in Laravel with this package?
- Add the `Auditable` trait to your Eloquent model and run the migration to create the `audits` table. The package automatically captures create, update, and delete events, including old/new values and timestamps. No extra code is needed for basic usage.
- Which Laravel versions does owen-it/laravel-auditing support?
- The package supports Laravel 11–13 (PHP 8.2+). Ensure your Laravel version matches the package’s requirements to avoid compatibility issues. Check the [GitHub repository](https://github.com/owen-it/laravel-auditing) for the latest version compatibility.
- Can I disable auditing for specific models or fields?
- Yes, you can disable auditing globally via config or per-model by setting `auditable = false` in the model. To exclude specific fields, use the `auditable` array in the model to list only the fields you want to track.
- How do I query audit logs for a specific model?
- Use the `Audit` facade or model to query logs. For example, `Audit::for(Model::class)->where('event', 'updated')->get()` retrieves all updates. The package provides methods like `whereChanged()`, `whereAdded()`, and `whereDeleted()` for granular filtering.
- Does this package support custom audit drivers (e.g., Redis or Elasticsearch)?
- Yes, the package supports custom drivers via the `AuditDriver` contract. You can implement your own driver for storage backends like Redis or Elasticsearch, though querying may require adjustments compared to the default database driver.
- How does performance impact scale with high-frequency model updates?
- Auditing triggers on every Eloquent event, which can impact performance for high-frequency operations. Mitigate this by disabling auditing for non-critical models or using a custom driver (e.g., async queue) to offload audit logging.
- Can I track soft-deleted models (deleted_at) in audit logs?
- Yes, the package captures soft deletes by default. Use methods like `withTrashed()` to query soft-deleted audit records. Hard deletes are also tracked, but you may need to configure this explicitly in your model.
- Are there built-in tools for pruning old audit logs?
- No, the package doesn’t include a built-in pruning tool, but you can manually delete old logs using Laravel’s scheduler or a custom command. Consider adding a retention policy (e.g., delete logs older than 6 months) to manage storage.
- How do I customize the user or metadata stored in audit logs?
- Use custom resolvers by implementing interfaces like `UserResolver` or `AttributeResolver`. For example, you can resolve the current user via a custom resolver or add metadata like tenant IDs or IP addresses to every audit entry.
- What alternatives exist for Laravel model auditing, and how does this compare?
- Alternatives include `spatie/laravel-activitylog` (more feature-rich but heavier) and `laravel-audit-log` (simpler but less flexible). This package stands out for its minimal setup, Laravel-native integration, and focus on granular field-level changes without excessive overhead.