PHPackages                             cyberland-international/laravel-global-audit - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. cyberland-international/laravel-global-audit

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

cyberland-international/laravel-global-audit
============================================

Simple Global Eloquent audit logging for Laravel

v1.0.7(6mo ago)0501↓42.9%MITPHPPHP ^8.1

Since Dec 15Pushed 6mo agoCompare

[ Source](https://github.com/cyberland-international/laravel-global-audit)[ Packagist](https://packagist.org/packages/cyberland-international/laravel-global-audit)[ RSS](/packages/cyberland-international-laravel-global-audit/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (8)Dependencies (2)Versions (9)Used By (0)

Laravel Global Audit
====================

[](#laravel-global-audit)

Simple, automatic Eloquent audit logging for Laravel applications.

This package records create, update and delete events for your Eloquent models into a dedicated `global_audit_logs` table.

---

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

[](#installation)

Require the package via Composer:

```
composer require cyberland-international/laravel-global-audit
```

Laravel 10+ will auto-discover the service provider.

If you prefer to register it manually, add this to `config/app.php`:

```
'providers' => [
    // ...
    Cyberland\GlobalAudit\GlobalAuditServiceProvider::class,
],
```

---

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

[](#configuration)

Publish the config and migration files:

```
php artisan vendor:publish --provider="Cyberland\GlobalAudit\GlobalAuditServiceProvider" --tag=config
php artisan vendor:publish --provider="Cyberland\GlobalAudit\GlobalAuditServiceProvider" --tag=migrations
```

This will publish:

- Config: `config/global-audit.php`
- Migration: `database/migrations/0000_00_00_000000_create_global_audit_logs_table.php`

Run the migration:

```
php artisan migrate
```

Open `config/global-audit.php` to adjust:

- Which models are audited
- Which attributes are ignored
- User resolution logic, etc. (depending on your config options)

---

Usage
-----

[](#usage)

Once installed, the package listens globally to Eloquent model events and records audit logs whenever a model is created, updated or deleted (according to your config).

You can query the audit logs via the `GlobalAuditLog` model:

```
use Cyberland\GlobalAudit\Models\GlobalAuditLog;

$logs = GlobalAuditLog::latest()->take(50)->get();
```

Each log entry typically contains:

- `user_id` (Auth ID)
- `http_method`
- `event` (e.g. `created`, `updated`, `deleted`)
- `model_type` and `model_id`
- `ip_address`
- `url`
- `user_agent`
- `changes` (JSONB) (contains `old`, `new`, and `dirty`)
- Timestamps (created\_at)

> Note: Adjust the exact fields above to match your `global_audit_logs` migration.

---

Scoping and Filtering
---------------------

[](#scoping-and-filtering)

You can filter logs by model, user, or event, for example:

```
use Cyberland\GlobalAudit\Models\GlobalAuditLog;
use App\Models\User;

$logs = GlobalAuditLog::where('model_type', User::class)
    ->where('event', 'updated')
    ->get();
```

Feel free to add your own scopes on the `GlobalAuditLog` model to encapsulate common queries.

---

Manual logging (facade)
-----------------------

[](#manual-logging-facade)

In addition to model lifecycle events, you can manually create audit logs for actions that do not involve Eloquent models (e.g. logins, logouts, custom API calls).

First, (optionally) register the facade alias in your application's `config/app.php`:

```
'aliases' => [
    // ...
    'GlobalAudit' => Cyberland\\GlobalAudit\\Facades\\GlobalAudit::class,
],
```

Then you can log events anywhere in your application, for example in an auth controller:

```
use GlobalAudit; // if alias is registered
use Illuminate\Http\Request;

class AuthController extends Controller
{
    public function login(Request $request)
    {
        $credentials = $request->only('email', 'password');

        if (! auth()->attempt($credentials)) {
            GlobalAudit::log(__METHOD__, [
                'status' => 'failed',
                'email' => $request->input('email'),
                'guard' => 'web',
            ]);

            return response()->json(['message' => 'Invalid credentials'], 401);
        }

        $user = auth()->user();

        GlobalAudit::log(__METHOD__, [
            'status' => 'success',
            'user_id' => $user->id,
            'email' => $user->email,
        ]);

        return response()->json(['message' => 'Logged in']);
    }
}
```

The `log` method signature is:

```
GlobalAudit::log(string $event, array $changes = [], ?\Illuminate\Contracts\Auth\Authenticatable $user = null): GlobalAuditLog
```

- `$event` is a short descriptor of what happened (e.g. `__METHOD__`, `'login'`, `'logout'`, `'api_call'`).
- `$changes` is any contextual data you want to store (sensitive keys listed in `global-audit.hidden` will be removed).
- `$user` is optional; when omitted, the current authenticated user (if any) is used.

---

### Middleware-based logging

[](#middleware-based-logging)

Instead of calling the facade in every controller method, you can centralize logging using the built-in middleware `Cyberland\GlobalAudit\Http\Middleware\GlobalAuditRequestMiddleware`. It records the controller action name in the `event` column and uses `config('global-audit.middleware')` for basic scoping.

Make sure the middleware alias is registered in your application:

```
// app/Http/Kernel.php

protected $routeMiddleware = [
    // ...
    'global.audit' => \Cyberland\GlobalAudit\Http\Middleware\GlobalAuditRequestMiddleware::class,
];
```

Then you can enable and scope it via your published `config/global-audit.php`:

```
// config/global-audit.php

'middleware' => [
    'enabled' => true,
    'only' => [
        'api/*',
    ],
    'except' => [
        'telescope*',
        'pulse*',
    ],
],
```

#### Route-level usage

[](#route-level-usage)

Apply the middleware directly on routes or route groups:

```
use App\Http\Controllers\AuthController;

Route::middleware('global.audit')->group(function () {
    Route::post('/login', [AuthController::class, 'login']);
    Route::post('/logout', [AuthController::class, 'logout']);
});
```

#### RouteServiceProvider (Laravel 10-style)

[](#routeserviceprovider-laravel-10-style)

If you organize routes in your `RouteServiceProvider`, you can attach the middleware at that level:

```
// app/Providers/RouteServiceProvider.php

use Illuminate\Support\Facades\Route;

public function boot(): void
{
    $this->routes(function () {
        Route::middleware(['api', 'global.audit'])
            ->prefix('api')
            ->group(base_path('routes/api.php'));
    });
}
```

#### Laravel 11+ bootstrap/app middleware

[](#laravel-11-bootstrapapp-middleware)

In Laravel 11+, if you're using the `bootstrap/app.php` style, you can register the middleware there when configuring the HTTP kernel:

```
// bootstrap/app.php

use Cyberland\GlobalAudit\Http\Middleware\GlobalAuditRequestMiddleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        api: __DIR__.'/../routes/api.php',
        // ...
    )
    ->withMiddleware(function (Illuminate\Foundation\Http\Kernel $kernel) {
        $kernel->aliasMiddleware('global.audit', GlobalAuditRequestMiddleware::class);
    })
    ->create();
```

After that, use `'global.audit'` on your routes as shown above.

#### Controller constructor

[](#controller-constructor)

You can also attach the middleware at the controller level so all actions on that controller are audited:

```
use Illuminate\Routing\Controller;

class AuthController extends Controller
{
    public function __construct()
    {
        $this->middleware('global.audit');
    }

    // all methods here will pass through GlobalAuditRequestMiddleware
}
```

---

Testing
-------

[](#testing)

Run your test suite (if present) with:

```
php artisan test
```

or, if using PHPUnit directly:

```
phpunit
```

---

Requirements
------------

[](#requirements)

- PHP ^8.1
- Laravel 10.x (`illuminate/support` and `illuminate/database` ^10.0)

---

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance66

Regular maintenance activity

Popularity17

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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

8

Last Release

201d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a37da50b35e325a241342ecf7072fc4244423bdae2904e62d28d8ee072b5051?d=identicon)[ronald-cyberland](/maintainers/ronald-cyberland)

---

Top Contributors

[![ronald-dytioco](https://avatars.githubusercontent.com/u/150100553?v=4)](https://github.com/ronald-dytioco "ronald-dytioco (13 commits)")

### Embed Badge

![Health badge](/badges/cyberland-international-laravel-global-audit/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M166](/packages/spatie-laravel-health)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)

PHPackages © 2026

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