Core
Audit Log
Wire Core includes an audit log for recording model changes and table-related events. It stores the event type, auditable record, user, old values, new values, metadata, and timestamp.
Wire Core includes an audit log for recording model changes and table-related events. It stores the event type, auditable record, user, old values, new values, metadata, and timestamp.
Install
The audit log is part of wire-core. If you installed wire-table or wire-forms, core is already installed.
Publish the config and migration:
php artisan vendor:publish --tag=wire-core-configphp artisan vendor:publish --tag=wire-core-migrationsphp artisan migrate
Register the audit subscriber in one of your application service providers:
use Illuminate\Support\Facades\Event;use NyonCode\WireCore\Audit\AuditEventSubscriber; public function boot(): void{ Event::subscribe(AuditEventSubscriber::class);}
Enable Auditing On A Model
Add HasAuditable to any Eloquent model you want to track.
use Illuminate\Database\Eloquent\Model;use NyonCode\WireCore\Audit\Concerns\HasAuditable; class Order extends Model{ use HasAuditable;}
The trait records Eloquent created, updated, and deleted events.
Exclude Or Include Columns
Use getAuditExclude() to hide noisy or sensitive columns for a single model.
class Order extends Model{ use HasAuditable; protected function getAuditExclude(): array { return ['cached_total', 'internal_token']; }}
Use getAuditInclude() when you want a whitelist.
protected function getAuditInclude(): array{ return ['status', 'total', 'assigned_user_id'];}
Global exclusions live in config/wire-core.php:
'audit' => [ 'exclude_columns' => [ 'password', 'remember_token', ],],
View Audit Entries
Each auditable model gets an audits() relation.
$entries = $order->audits()->latest()->get();
Audit entries expose helpers for common queries:
use NyonCode\WireCore\Audit\AuditEntry; AuditEntry::forRecord($order)->get();AuditEntry::forEvent('updated')->get();AuditEntry::byUser($user->id)->get();AuditEntry::olderThan(90)->delete();
To show a row-level audit trail in a Wire Table, add the built-in action:
use NyonCode\WireCore\Audit\Actions\AuditTrailAction; return $table ->model(Order::class) ->actions([ AuditTrailAction::make(), ]);
The action opens a slide-over with the record history.
Manual Audit Events
You can dispatch audit events manually for operations that do not go through an audited model event.
use NyonCode\WireCore\Audit\Events\BulkActionExecuted; event(new BulkActionExecuted( actionName: 'archive', modelType: Order::class, recordIds: $orders->modelKeys(), success: true, metadata: ['source' => 'orders-table'],));
For a single cell update:
use NyonCode\WireCore\Audit\Events\InlineCellUpdated; event(new InlineCellUpdated( modelType: Order::class, recordId: $order->id, column: 'status', oldValue: 'draft', newValue: 'approved',));
Disable Temporarily
Disable audit logging during imports, seeders, or maintenance jobs:
use NyonCode\WireCore\Audit\AuditLogger; AuditLogger::withoutAuditing(function () { Order::query()->update(['synced_at' => now()]);});
Retention
Set a retention period in days:
'audit' => [ 'retention_days' => 180,],
Then prune old entries from a scheduled command or job:
use NyonCode\WireCore\Audit\AuditLogger; app(AuditLogger::class)->prune();
Configuration
| Key | Default | Description |
|---|---|---|
enabled |
true |
Global on/off switch |
model |
AuditEntry::class |
Custom audit entry model |
user_model |
App\Models\User |
User model for the user() relation |
events |
null |
null logs all supported events; array logs only selected event types |
exclude_columns |
password, remember_token |
Global column exclusions |
retention_days |
null |
Number of days to keep entries |
Supported event types are created, updated, deleted, bulk_action, and cell_updated.
See Configuration for the full config reference.