Download the PHP package ss-ipg/laravel-auditable without Composer
On this page you can find all versions of the php package ss-ipg/laravel-auditable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-auditable
Laravel Auditable
Declarative model audit logging for Laravel using PHP attributes.
Overview
Laravel Auditable provides a simple, attribute-based approach to audit logging for Eloquent models. Mark any model with the #[Auditable] attribute and all create, update, and delete events are automatically logged with detailed change tracking.
Features
- Declarative
#[Auditable]attribute on models - Tracks
created,updated,deleted,soft_deleted, andrestoredevents - Old/new value tracking for updates
- Column filtering (include, exclude, redact)
- Per-model event filtering
- Soft delete detection
- Boolean cast normalization
- JSON output for log aggregation (Datadog, Splunk, etc.)
- Extensible context providers for custom metadata
- Configurable formatters
Requirements
- PHP 8.3+
- Laravel 11+
Installation
Publish the configuration file:
Quick Start
1. Configure a log channel
Add an audit channel to config/logging.php:
2. Add the attribute to a model
3. Enable audit logging
In your .env file:
That's it! All changes to the model will now be logged.
Configuration
Note: Set
environmentsto['*']to enable audit logging in all environments regardless ofAPP_ENV.
Attribute Options
The #[Auditable] attribute accepts several options:
| Option | Type | Default | Description |
|---|---|---|---|
columns |
?array |
null |
Only audit these columns. null = all columns. |
exclude |
array |
[] |
Exclude these columns from auditing. |
redact |
array |
[] |
Log that column changed, but show [REDACTED] instead of values. |
events |
array |
All events | Which events to audit. |
withOriginal |
bool |
true |
Include original values in update logs. |
Examples
Log Output
Each audit entry is a JSON object with the following structure:
Default Fields
These fields are automatically included in every audit entry:
| Field | Source |
|---|---|
action |
The event type (created, updated, deleted, etc.) |
context |
"web" or "cli" based on how the application is running |
model |
The fully-qualified model class name |
model_id |
The model's primary key value |
user_id |
auth()->id() — the authenticated user, or null if unauthenticated |
ip |
request()->ip() — the client IP address |
timestamp |
ISO 8601 formatted timestamp |
Changes Structure
The changes field varies by event type:
created: All tracked attribute valuesupdated: Only changed attributes witholdandnewvalues (or just new values ifwithOriginal: false)deleted,soft_deleted,restored: Only the model ID ({"id": 123})
Soft Delete Detection
When a model uses Laravel's SoftDeletes trait, the package automatically distinguishes between soft deletes and hard deletes:
soft_deleted: Logged whendelete()is called on a soft-deletable modeldeleted: Logged whenforceDelete()is called, or when deleting a model withoutSoftDeletesrestored: Logged whenrestore()is called on a soft-deleted model
No configuration is needed—the package detects the SoftDeletes trait automatically.
Cast Normalization
The package respects your model's $casts to prevent false-positive change detection. For example:
This applies to boolean, integer, float, string, array, and json casts.
Context Providers
Context providers allow you to add custom metadata to every audit log entry. Create a class that implements AuditContextProvider:
Register the provider in config/auditable.php:
Custom Formatters
To customize the log output format, create a class that implements AuditFormatter:
Register it in config/auditable.php:
Auditing Pivot Tables
Standard attach(), detach(), and sync() operations bypass Eloquent model events. To audit pivot table changes, use a custom Pivot model:
Then reference it in your relationships:
Testing
The package provides Audit::fake() for testing auditable models without writing to actual log files.
Basic Usage
Available Assertions
Entry Structure
Each captured entry contains:
Known Limitations
- Mass operations bypass events:
Model::insert(),Model::update()(query builder), and similar mass operations do not fire Eloquent events and will not be audited. Use model instances for auditable operations. - Timestamp columns excluded:
created_at,updated_at, anddeleted_atare always excluded from change tracking (the audit log has its own timestamp).
License
MIT License. See LICENSE for details.
All versions of laravel-auditable with dependencies
illuminate/contracts Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/log Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0