PHPackages                             stealthfirems/laravel-audit-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. stealthfirems/laravel-audit-module

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

stealthfirems/laravel-audit-module
==================================

Auditor module for Laravel applications.

v0.2.4(12mo ago)049MITPHP

Since May 9Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/StealthFireMS/laravel-audit-module)[ Packagist](https://packagist.org/packages/stealthfirems/laravel-audit-module)[ RSS](/packages/stealthfirems-laravel-audit-module/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (16)Used By (0)

laravel auditing module
=======================

[](#laravel-auditing-module)

A module to provide the ability and flexibility to easily audit events and actions that happen within your Laravel application. Designed around StealthFireMS Laravel applications

Installation
------------

[](#installation)

install the package via composer:

```
composer require stealthfirems/laravel-audit-module
```

run this

```
php artisan vendor:publish --provider="StealthFireMS\LaravelAuditModule\Providers\AuditModuleServiceProvider" --tag="AuditModule"
```

Once you've done this, run your migrations. This will create a table called `audit_logs`.

```
php artisan migrate

```

Configuration
-------------

[](#configuration)

Variables for your root.env file

Base template

```
AUDIT_MODULE_RETENTION=30
AUDIT_MODULE_OBFUSCATE_IP=false
AUDIT_MODULE_TABLE_NAME=audit_logs # table name
```

### Obfuscating the IP address for compliance

[](#obfuscating-the-ip-address-for-compliance)

You can easily obfuscate IP addresses that are submitted to the database by setting the `AUDIT_MODULE_OBFUSCATE_IP`variable in your `.env` file to `true`. This will strip the first two octets of an IP address, ensuring it meets various compliance laws, such as GDPR. Behind the scenes this switches the default IP address fetcher with an Obfuscated IP fetcher.

### Setting the retention duration

[](#setting-the-retention-duration)

You can define how many days your logs should be kept for by setting the `AUDIT_MODULE_RETENTION` in your `.env` file. If you want to keep all logs indefinitely, set this to `0`.

Every time the audit logs are pruned, this will be recorded as an audit log itself.

Usage
-----

[](#usage)

There are multiple ways you can use this package. The most common way is to use the `audit` helper function.

### Using the global audit helper

[](#using-the-global-audit-helper)

The `audit` helper function is an easy way to quickly log to the audits table. This function takes a string as the first argument, and an optional array (context) as the second argument. This will only work if you don't already have a global function called `audit`.

Example 1:

```
audit('login', [
    'severity' => 'info',
]);
```

Example 2:

```
audit('logout', [
    'severity' => 'info',
    'context'=> '$FailedEmailAddress',
]);
```

Helper Break Down:

```
audit('Action be performed', [
    'severity' => 'serverity of the action being logged',
    'context' => 'Extra content being stored in the log'
]);
```

Table Break down

```
$table->bigIncrements('id'); // Primary key for the log entry

$table->string('action')->index(); //Action being performed in the log

$table->string('severity')->index(); // Severity level of the log | default is 'info'

$table->longText('context')->nullable()->default(null); // Contextual information about the action

$table->string('type')->; //User or system action | System by default unless user is specified

$table->unsignedBigInteger('user_id')->index()->nullable(); // ID of the user performing the action

$table->string('guard')->nullable(); // Guard used for authentication

$table->string('ip_address'); // IP address of the user performing the action

$table->timestamp('created_at')->useCurrent(); // Timestamp of when the log was created
```

### Binding to events

[](#binding-to-events)

If you want to audit an event that happens within your application, you can do so by using the `IsAuditableEvent`interface. Coupled with `AuditableEvent`, this will automatically log the event to the audit log.

Here's an example of an event that utilises the `IsAuditableEvent` interface:

```
// import our contract & trait
use StealthFireMS\LaravelAuditModule\Contracts\IsAuditableEvent;
use StealthFireMS\LaravelAuditModule\Traits\AuditableEvent;

class MyCustomEvent implements IsAuditableEvent
{
    use AuditableEvent;

    public function handle()
    {
        // ToDo: your event logic.
    }

    // optional - by default will be handled by the AuditableEvent trait
    public function getAuditMessage(): string
    {
        return 'Action performed';
    }

    // optional - by default will be handled by the AuditableEvent trait
    public function getAuditContext(): array
    {
        return ['more_data' => 'Goes here'];
    }
}
```

### Using the `AuditableModel` trait on Models

[](#using-the-auditablemodel-trait-on-models)

If you have a model that you'd like to be audited on change, you can use the `AuditableModel` trait. By default, this will record all creations, updates and deletions for this model to the audit log. This uses Laravel model observers to listen for changes. By default, the `created_at` and `updated_at` columns are excluded from auditing.

```
use Illuminate\Database\Eloquent\Model;
use StealthFireMS\LaravelAuditModule\Traits\AuditableModel;

class YourModel extends Model
{
    use AuditableModel;

    /**
    * An array of columns that shouldn't be audited.
    * @var array|string[]
    */
    protected array $excludedFromAuditing = [
        'created_at',
        'updated_at',
    ];
}
```

#### Customising the `AuditableModel` functionality

[](#customising-the-auditablemodel-functionality)

If you'd like to expand the functionality of the `AuditableModel` trait, you can override its observer by configuring the `observer` key in the config file. This will allow you to create your own model observer.

```
use StealthFireMS\LaravelAuditModule\Observers\AuditableModelObserver as BaseObserver;

class AuditableObserver extends BaseObserver
{
    // your custom classes here
    // see https://laravel.com/docs/11.x/eloquent#observers for more information
}
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security-related issues use the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance52

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

15

Last Release

364d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/731fcc5f9ce92dd41243818a978e7b6e1e29c8b16fe0d4ac944c2535b21d78b1?d=identicon)[StealthFireMS](/maintainers/StealthFireMS)

---

Top Contributors

[![StealthFireMS](https://avatars.githubusercontent.com/u/160486165?v=4)](https://github.com/StealthFireMS "StealthFireMS (22 commits)")

---

Tags

laravelAuditstealthfirems

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/stealthfirems-laravel-audit-module/health.svg)

```
[![Health](https://phpackages.com/badges/stealthfirems-laravel-audit-module/health.svg)](https://phpackages.com/packages/stealthfirems-laravel-audit-module)
```

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[tapp/filament-auditing

Filament Laravel Auditing plugin.

113379.4k2](/packages/tapp-filament-auditing)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

97139.6k2](/packages/nickurt-laravel-akismet)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
