govelid / laravel-multi-auditable
A Laravel package to create flexible auditable migrations and traits
Requires
- php: >=7.4
README
This package simplifies the management of models that use audit trails, enabling multiple audit tables for each module within your Laravel web application.
Support the Project
If you find this package useful, consider supporting its development:
Installation
-
Install the package via composer:
composer require govelid/laravel-multi-auditable
-
Example: Run the following Artisan command to create the necessary files:
php artisan make:auditable ProjectAuditable
This will generate:
- A migration file for the table
project_auditables
. - A Trait file
ProjectAuditableTrait
. - A Model file
ProjectAuditable
.
- A migration file for the table
-
Run migration
-
To add audit trail functionality to the
Project
model, simply include the trait:use ProjectAuditableTrait;
Customization
You can override the following methods in your model for further customization:
Timestamp Attributes
Override the default timestamp attributes (e.g., created_at
, updated_at
):
protected function getTimestampAttributes() { return ['updated_at', 'created_at']; }
Audit Record ID
Specify the audit record ID (defaults to id
):
public function getAuditRecordId() { return $this->id; }
Audit Fields Notes
Add custom notes for audit trails:
public function getAuditFieldsNotes() { return $this->id; }
Audit Fields for Delete
Define the fields to be logged during deletion:
public function getAuditFieldsForDelete() { return ['id']; }