owen-it/laravel-auditing
Track and review changes to your Eloquent models with minimal setup. Laravel Auditing stores a history of updates, helps spot discrepancies or suspicious activity, and makes it easy to retrieve and display audit records in your Laravel app.
creating, updating, deleting, restoring, retrieved) to capture model changes, aligning well with Laravel’s built-in event system. This ensures minimal intrusion into existing model logic.Auditable trait, keeping model classes clean while centralizing audit-related logic. The Audit model handles storage and retrieval, adhering to the Single Responsibility Principle (SRP).use Auditable).audits table (migration provided), which must be accounted for in deployment pipelines. Schema changes are backward-compatible within major versions.Auditable trait.AttributeRedactor or custom resolvers to sanitize data.cursor()) or index auditable_id/created_at columns.exclude config) suffice, or are custom rules needed?AttributeRedactor be configured?AuditDriver interface.Auditable trait or Audit model.Log::info()) to identify gaps (e.g., missing events, PII exposure).User updates," "exclude password fields").composer require owen-it/laravel-auditing.php artisan vendor:publish --provider="OwenIt\Auditing\AuditingServiceProvider".php artisan migrate.Auditable trait in target models:
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
use OwenIt\Auditing\Traits\Auditable;
class User extends Model implements AuditableContract
{
use Auditable;
}
config/auditing.php:
'exclude' => [
'password',
'remember_token',
],
IpResolver, UserResolver) for custom metadata.AttributeRedactor for sensitive fields.getAuditEvents() for model-specific event filtering.audits table from legacy logs using the Audit model’s create() method.updating). Mitigation: Prioritize event listeners or use middleware.audits() for a model).User) to validate the setup./audits?model=User) and pruning (php artisan audit:prune).auditing.php) reduces maintenance overhead. Changes to audit policies (e.g., new exclusions) require config updates.php artisan audit:list (shows audit events), tinker for inspecting Audit models.auditable_id, created_at.cursor()) for large datasets.php artisan audit:prune --days=30.AuditDriver for NoSQL or log-based storage.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database downtime | Lost audit logs during outages. | Use a queue-based driver with retries. |
| Event listener failures | Missing audits for critical events. | Wrap listeners in try-catch; alert on failures. |
| Schema migration errors | Broken audit retrieval. | Test migrations in staging; backup audits table. |
| Performance degradation |
How can I help you explore Laravel packages today?