govelid/laravel-multi-auditable

A Laravel package to create flexible auditable migrations and traits

1.1.5 2025-02-11 05:34 UTC

This package is auto-updated.

Last update: 2025-06-11 06:28:22 UTC


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:

Support Me

Installation

  1. Install the package via composer:

    composer require govelid/laravel-multi-auditable
  2. 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.
  3. Run migration

  4. 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'];
}