Download the PHP package mxnwire/laravel-audit-log without Composer
On this page you can find all versions of the php package mxnwire/laravel-audit-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mxnwire/laravel-audit-log
More information about mxnwire/laravel-audit-log
Files in mxnwire/laravel-audit-log
Package laravel-audit-log
Short Description Audit log viewer layered on top of spatie/laravel-activitylog
License MIT
Informations about the package laravel-audit-log
mxnwire/laravel-audit-log
Audit log viewer and logger layered on top of spatie/laravel-activitylog.
Spatie owns the storage (activity_log table, polymorphic causer/subject, and the activitylog:clean prune command). This package adds:
- An
audit_log()helper andAuditLogServicethat freeze actor identity and request context at write time. - A built-in viewer UI (filterable table, no JS build step required) protected by a permission gate.
AuditMetadata/Changevalue objects for structured before/after diffs in thepropertiescolumn.
Requirements
| Dependency | Version |
|---|---|
| PHP | ^8.1 |
| Laravel | 10 or 11 |
| spatie/laravel-activitylog | ^4.0 |
Installation
1. Install the package via Composer:
The service provider is auto-discovered — no manual registration needed.
2. Install and run spatie's migration:
If you have not already done so for spatie/laravel-activitylog:
3. Publish the package assets (optional but recommended):
This copies two things:
| Source | Destination |
|---|---|
config/audit-log.php |
config/audit-log.php |
resources/views/ |
resources/views/vendor/audit-log/ |
You only need to publish if you want to customise views or the config file. The package works out of the box without publishing.
Configuration
After publishing, edit config/audit-log.php:
Usage
Logging an audit event
Use the global helper (available automatically — no import needed):
Renamed in 2.0. The helper is now
audit_log()and the service isAuditLogService. The oldactivity_log()helper has been removed — migrate any remaining calls toaudit_log().
Or inject the service directly:
Signature
The dotted action maps to spatie's two indexable columns:
The __actor and __request context is merged into spatie's properties JSON column automatically. __actor is the actor snapshot; __request is built from the request_context config (see below):
Configuring __request
The request_context array in config/audit-log.php is the single source of
truth for what lands in __request. List the built-in properties you want by
name — the package ships resolvers for method, route, url, ip,
user_agent, query, and body. query is enabled by default; body is not,
since it can carry secrets. To capture anything else, add a keyed entry with your
own fn ($request) => mixed resolver (this also overrides a built-in of the same
name). Header-sourced values go under the headers group, mapping a property
name to the inbound header:
Resolved values land in __request (header values under __request.headers); a
null/empty result is dropped, so a request without a given header — or an empty
query string — simply omits that property.
Redacting secrets
Logged query and body input is filtered through the redact list before
storage, so credentials never reach the log. Matching is case-insensitive and
recurses into nested arrays; a matched value becomes "[REDACTED]". The defaults
cover common credential fields (password, token, secret, …) — edit the list
to fit your app:
To set a value manually (overriding the configured source), pass a field of the
same name in the metadata bag — the explicit value always wins and is stored only
under __request:
Adding structured metadata
Use AuditMetadata to attach typed field-level detail to a log entry.
Arbitrary fields:
Before/after diff for a specific field:
Stored in properties as:
Auto-diff two arrays (keeps only changed keys):
You can restrict which keys are diffed with the optional third argument:
Fluent chaining:
Viewing logs
The package registers two routes automatically:
| Route | Named route | Description |
|---|---|---|
GET /mxn/audit-logs |
audit-log.index |
Viewer page |
GET /mxn/audit-logs/data |
audit-log.data |
JSON data endpoint for the table |
Both routes are protected by auth plus a gate callback. The gate config is a closure receiving the authenticated user and returning a boolean; it allows only users whose role is admin by default. Override it in the published config — e.g. fn ($user) => $user?->can('AUDIT_LOGS_ALL') ?? false.
Customisation
Custom viewer layout
To embed the viewer inside your own app shell, set layout in the config to any Blade layout that yields content and script:
Your layout must contain:
Custom route prefix
The named routes (audit-log.index, audit-log.data) follow the prefix automatically.
Custom role resolver
If your app does not use a role or urole attribute directly on the User model:
Custom audit type registry
The viewer's filter dropdowns (log names, events, subject types) come from the class named in the registry config key. By default this is the DB-backed AuditTypeRegistry, which SELECT DISTINCTs the live activity_log table at runtime — zero setup, but it only ever surfaces values that have already been logged.
To serve the options from a fixed vocabulary instead, extend AbstractAuditTypeRegistry, declare your dotted resource.verb actions as constants, and map each resource to its subject model:
Then point the config at it:
The option lists are derived from those constants via reflection, so new RESOURCE_VERB constants enrol automatically.
For full control you can implement AuditTypeRegistryContract directly instead of extending the abstract class — it requires logNames(): array, events(): array, and subjectTypes(): array. The provider binds the contract with bindIf, so an explicit container binding in a service provider still takes precedence over the config value:
Development
Running the tests
The test suite uses Orchestra Testbench and an in-memory SQLite database — no external database or running Laravel app is required.
1. Install dev dependencies (first time only):
2. Run the full suite:
Or call PHPUnit directly:
3. Run a single suite:
4. Run a single test file:
5. Run a single test by name:
Test structure
| Path | What it covers |
|---|---|
tests/Unit/AuditMetadataTest.php |
AuditMetadata value object — make, diff, with |
tests/Unit/ChangeTest.php |
Change value object — serialisation |
tests/Feature/AuditLogServiceTest.php |
AuditLogService end-to-end against a real SQLite DB |
tests/TestCase.php |
Base case — boots Testbench, runs spatie migrations in-memory |
License
MIT
All versions of laravel-audit-log with dependencies
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
spatie/laravel-activitylog Version ^4.0