owen-it/laravel-auditing
Audit Eloquent model changes in Laravel with a simple trait. Automatically record create/update/delete events, track who/when/what changed, and retrieve audit history for reports, compliance, and anomaly detection. Flexible drivers and rich metadata support.
Pros:
creating, updating, deleting, restoring) to capture model changes. Aligns perfectly with Laravel’s event-driven architecture.Auditable trait on models to enable auditing. No need for manual event listeners or middleware.UserResolver, AttributeResolver). Allows granular control over what gets audited.retrieved, saved, deleted) and supports custom events via getAuditEvents().UserResolver) and multi-user audits (since v7.0.0).AttributeRedactor (e.g., hiding passwords, tokens).Cons:
audits table with specific columns (e.g., auditable_id, auditable_type, user_id, event, old_values, new_values). Schema migrations must be managed carefully.audits table to an existing production database requires downtime or careful zero-downtime migration strategies (e.g., blue-green deployments).audit() method or config).old_values, new_values for text fields).prune() method).UserResolver interface and dependency injection.saving vs. updating). Test thoroughly.AttributeEncoder for custom handling.UserResolver may be needed.exclude config or AttributeRedactor.audits table migration be run in production without downtime?Auditable trait integrates directly into model classes.ModelEvents). No conflicts if other listeners are properly ordered.PDO and database extensions (standard for Laravel).composer require owen-it/laravel-auditing
php artisan vendor:publish --provider="OwenIt\Auditing\AuditingServiceProvider"
php artisan migrate
config/auditing.php (e.g., default events, excluded attributes, resolvers).Auditable trait on target models:
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
use OwenIt\Auditing\Traits\Auditable;
class User extends Model implements AuditableContract
{
use Auditable;
}
class User extends Model
{
use Auditable;
public function getAuditEvents()
{
return ['created', 'updated', 'deleted']; // Custom events
}
public function getAuditExcludes()
{
return ['password', 'api_token']; // Exclude sensitive fields
}
}
use OwenIt\Auditing\Contracts\UserResolver;
class CustomUserResolver implements UserResolver
{
public function resolve()
{
return auth()->user() ?: new User(); // Fallback for unauthenticated
}
}
config/auditing.php:
'user
How can I help you explore Laravel packages today?