kamel / laravel-auditable
v0.0.1
2026-02-10 17:35 UTC
Requires
- php: ~8.2
- illuminate/console: ^12.0
- illuminate/database: ^12.0
- illuminate/filesystem: ^12.0
- spatie/data-transfer-object: ^3.9
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^10.0
- phpunit/phpunit: ^11.5
- psy/psysh: ^0.12.0
README
A Laravel package that provides automatic auditing for Eloquent models.
Package Installation
1. Install Package
composer require kamel/laravel-auditable
Usage
Basic Usage
Add the Auditable trait to any Eloquent model:
<?php namespace App\Models; use Kamel\Auditable\Traits\Auditable; use Illuminate\Database\Eloquent\Model; class User extends Model { use Auditable; protected $fillable = ['name', 'email', 'password']; }
How It Works
Once the trait is added, all Eloquent operations are automatically audited:
// Creating a user - triggers audit $user = User::create([ 'name' => 'John Doe', 'email' => 'john@example.com' ]); // Updating a user - triggers audit $user = User::find(1); $user->name = 'Jane Doe'; $user->save(); // Mass update - triggers audit User::where('id', 1)->update(['email' => 'jane@example.com']);
Event Handling
The package dispatches AuditWasTriggered events. Listen for them.
Audit Data Structure
Each audit record contains:
model_type: The audited model classmodel_id: The model's primary keyold_values: JSON of previous valuesnew_values: JSON of new valuesuser_type: User model class (if authenticated)user_id: User ID (if authenticated)url: Request URL
Development Setup
Build Docker Container
make build
Run Tests
make test
Clean Environment
make clean
Available Make Commands
make build- Build the Docker containermake test- Run the test suite with testdox outputmake clean- Remove Docker containers and images