- Can AlliGovender’s Auditor Bundle work with Laravel, or is it only for Symfony?
- This bundle is Symfony-centric but can be adapted for Laravel. You’d need to replace Symfony’s EventDispatcher with Laravel’s service providers, rewrite annotations for Eloquent models, and bridge the user context (e.g., Auth facade). The core audit logic (event listeners) can be extracted for Laravel use.
- How do I install this bundle in a Laravel project?
- Since it’s Symfony-focused, you’ll need to manually integrate the underlying `auditor` library. Start by installing via Composer (`composer require alli-govender/auditor-bundle`), then adapt its Doctrine listeners to Laravel’s event system (e.g., `Model::saved()` or `Model::deleted()`).
- Which Laravel versions and PHP versions does this bundle support?
- The bundle itself requires PHP 7.2+ and Symfony 3.4+. For Laravel, compatibility depends on your custom integration, but PHP 7.4+ is recommended. Test thoroughly with your Laravel version (e.g., 8.x, 9.x) due to Symfony dependencies.
- How do I configure which Eloquent models to audit in Laravel?
- In Laravel, you’d replace Symfony’s `@Audited` annotations with traits or model observers. For example, add a `HasAudit` trait to models or use `Model::observe()` to trigger audit logic on events like `creating`, `updating`, or `deleting`.
- Will this bundle slow down my Laravel application in production?
- Audit logging adds database writes for every tracked change, which can impact performance. Mitigate this by batching writes, using queue-based async logging (e.g., Laravel Queues), or auditing only critical models. Monitor write-heavy workloads closely.
- Does this bundle automatically create audit tables in Laravel migrations?
- No—it’s designed for Symfony’s schema updates. In Laravel, you’d need to manually create audit tables (e.g., `audit_entries`) in migrations. Use Laravel’s `Schema::create()` or a package like `laravel-migrations-generator` to define them.
- How do I track the user who made changes in Laravel’s audit logs?
- Use Laravel’s `Auth` facade to fetch the authenticated user’s ID in your custom audit logic. For example, inject `Auth::id()` into your observer or trait methods. Anonymous users can be logged as `null` or a default value like `system`.
- Are there alternatives to this bundle for Laravel that don’t require Symfony?
- Yes. Consider `owen-it/laravel-auditing` (Eloquent-based), `spatie/laravel-activitylog` (flexible logging), or `laravel-audit-log` for simpler needs. These are Laravel-native and avoid Symfony dependencies entirely.
- How do I test audit logs in Laravel unit/feature tests?
- Mock the audit logic in tests by overriding the observer/trait methods or using Laravel’s `partialMock`. For assertions, compare database snapshots (e.g., `DatabaseMigrations`) or verify audit entries exist with `AuditEntry::where('user_id', $user)->exists()`.
- What’s the maintenance status of this fork (alli-govender/auditor-bundle)?
- The fork lacks community traction (few stars) compared to the original `damienharper/auditor-bundle`. Check the GitHub issues for activity or consider the original bundle if Symfony compatibility isn’t a blocker. For Laravel, a custom implementation may be more sustainable.