- How do I enable activity logging for an Eloquent model in Laravel?
- Use the `LogsActivity` trait in your model class. The package automatically logs `created`, `updated`, `deleted`, and `restored` (if using SoftDeletes) events. No additional configuration is needed unless you customize log names or ignored/redacted attributes.
- Does this package work with Laravel 12+ and PHP 8.3+?
- Yes, the package explicitly requires Laravel 12+ and PHP 8.3+. If your project uses an older version, you’ll need to upgrade to use this package. Check the [repository](https://github.com/foxen-digital/laravel-model-activity-log) for potential backporting efforts.
- Can I filter or query the activity logs beyond basic retrieval?
- The package stores logs in a single `activity_log` table but does not expose a query builder. You’ll need to manually query the table or extend the package. For complex filtering (e.g., by user or time range), consider adding scopes or using Laravel’s query builder directly on the `activity_log` table.
- How do I ignore specific attributes from being logged in updates?
- Define a `protected $ignoreActivityLogAttributes` property in your model and list the attributes to exclude. For example, `$ignoreActivityLogAttributes = ['updated_at', 'password']` will skip these fields when logging updates or creates.
- What happens if no authenticated user is present when logging an action?
- Actions performed without an authenticated user (e.g., via CLI, queues, or API calls) are automatically attributed to the `System` causer. This ensures logs are never left unattributed, even in headless environments.
- How do I redact sensitive data (e.g., passwords) in activity logs?
- Use the `protected $redactedActivityLogAttributes` property in your model. The attribute keys will still appear in logs, but their values will be replaced with `[REDACTED]`. For example, `$redactedActivityLogAttributes = ['password', 'credit_card']` will mask these fields.
- Is there a way to prune old activity logs automatically?
- Yes, the package supports pruning old logs via Time-To-Live (TTL) policies. Configure retention rules in the `foxen_activitylog.php` config file, then schedule a Laravel command or cron job to run `php artisan activitylog:prune` periodically.
- Will this package impact performance for high-frequency models?
- Logging every update (including old/new attribute diffs) can introduce overhead, especially for models with frequent writes. Test performance under load, and consider disabling logging for non-critical models or batching log writes if needed.
- Can I customize the log table name or schema?
- The package uses a default `activity_log` table with a fixed schema. To customize the table name, override the `getActivityLogTable()` method in your model. Schema changes require manual migration adjustments, as the package does not support dynamic schema extensions.
- What are the alternatives to this package, and how does it compare?
- Alternatives include `laravel-audit` and `spatie/laravel-audit-logs`, which offer more query flexibility and sometimes additional features like real-time notifications. This package prioritizes simplicity and minimal setup, while alternatives may provide better scalability for complex auditing needs.