laravel-audit maintained by bhhaskin
Description
Audit trail package for Laravel applications with UUID support.
Author
Last update
2025/11/02 09:06
(dev-main)
License
Downloads
25
Laravel Audit
Lightweight audit trail package for Laravel applications.
Features
- Records
created,updated,deleted, andrestoredevents for any model. - Stores both numeric primary keys and UUIDs for audits, auditable models, and users.
- Captures before/after state, request metadata, and user attribution.
- Ships with ready-to-run migrations plus publishable stubs and configuration.
Installation
composer require bhhaskin/laravel-audit
Laravel auto-discovers the service provider. For older versions add LaravelAudit\AuditServiceProvider::class to the providers array in config/app.php.
Publish Assets
php artisan vendor:publish --provider="LaravelAudit\AuditServiceProvider" --tag=laravel-audit-config
php artisan vendor:publish --provider="LaravelAudit\AuditServiceProvider" --tag=laravel-audit-migrations
Run the migration:
php artisan migrate
Usage
- Add the
Auditabletrait to any Eloquent model that you want to track. - Ensure the model has a
uuidcolumn populated via the includedHasAuditUuidtrait or your own logic.
use Illuminate\Database\Eloquent\Model;
use LaravelAudit\Traits\Auditable;
use LaravelAudit\Traits\HasAuditUuid;
class Post extends Model
{
use HasAuditUuid;
use Auditable;
}
Audits are exposed through the audits() relationship:
$post = Post::first();
foreach ($post->audits as $audit) {
echo $audit->uuid; // Frontend-friendly identifier
}
Configuration
Published configuration (config/audit.php) lets you:
- Enable/disable the logger or specific events.
- Ignore fields such as timestamps when diffing changes.
- Add default metadata and provide a custom user resolver.
The default user resolver defers to Laravel's auth() helper. Implement a custom resolver by binding a callable class and updating user_resolver in the config.
Events
Two framework events are fired for each audit lifecycle:
LaravelAudit\Events\AuditRecording(before persistence) exposes the proposed payload for last-minute tweaks.LaravelAudit\Events\AuditRecorded(after persistence) includes the savedAuditmodel instance.
Listen for these events to trigger notifications, broadcast changes, or enrich metadata.
License
MIT © Bryan
Testing
composer install
composer test