PHPackages                             codersandip/laravel-audit-pro - 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. codersandip/laravel-audit-pro

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

codersandip/laravel-audit-pro
=============================

An advanced activity and audit logging system for Laravel applications with admin UI, export, and queue support.

v1.0.0(2mo ago)01↓100%MITPHPPHP ^8.2

Since Mar 9Pushed 2mo agoCompare

[ Source](https://github.com/codersandip/laravel-audit-pro)[ Packagist](https://packagist.org/packages/codersandip/laravel-audit-pro)[ Docs](https://github.com/codersandip/laravel-audit-pro)[ RSS](/packages/codersandip-laravel-audit-pro/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

🛡️ Laravel Activity &amp; Audit Pro
===================================

[](#️-laravel-activity--audit-pro)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0a76a06ad560521e1287ad5160b4e6dbd4bad19b38c4162ad6307ed07061b218/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64657273616e6469702f6c61726176656c2d61756469742d70726f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codersandip/laravel-audit-pro)[![Total Downloads](https://camo.githubusercontent.com/24737e4a5f0840d76fef87c5788bb116280d55b8e9e8468020da4dc5cea0bd56/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f64657273616e6469702f6c61726176656c2d61756469742d70726f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/codersandip/laravel-audit-pro)[![License](https://camo.githubusercontent.com/aa9167394bb568e5d57465a4790326326d6ec278f04c45e197936eefb4b84822/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f64657273616e6469702f6c61726176656c2d61756469742d70726f2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

An **advanced activity and audit logging system** for Laravel 9–12.
Track every model change, capture rich request metadata, and browse logs through a beautiful dark-themed admin panel — all with zero configuration needed to get started.

---

✨ Features
----------

[](#-features)

FeatureDescription🔍 **Model Tracking**Auto-detect create / update / delete / restore events📊 **Before &amp; After Diff**Store changed fields only — clean JSON diffs👤 **User Tracking**Auth user ID, name, email (multi-guard support)🌐 **Request Metadata**IP address, device type, browser, OS🎨 **Admin Panel UI**Beautiful dark Bootstrap 5 UI with search, filters, pagination📤 **CSV Export**Date-range and filter-based CSV export⚡ **Queue Support**Optional async logging via Laravel Queues🔒 **Security**Middleware protection, configurable prefix🧹 **Log Retention**Configurable pruning via Artisan command📦 **Publishable**Config, migrations, views, and assets---

📋 Requirements
--------------

[](#-requirements)

- PHP 8.2+
- Laravel 9.x / 10.x / 11.x / 12.x
- `jenssegers/agent` (for device/browser detection — installed automatically)

---

🚀 Installation
--------------

[](#-installation)

### Step 1 — Require the package

[](#step-1--require-the-package)

```
composer require codersandip/laravel-audit-pro
```

> **Laravel 9+** auto-discovers the service provider via `extra.laravel` in `composer.json`.
> No manual provider registration needed.

---

### Step 2 — Publish the config

[](#step-2--publish-the-config)

```
php artisan vendor:publish --tag=audit-pro-config
```

This publishes `config/audit-pro.php` to your application.

---

### Step 3 — Publish &amp; run migrations

[](#step-3--publish--run-migrations)

```
php artisan vendor:publish --tag=audit-pro-migrations
php artisan migrate
```

Or run the migration directly without publishing:

```
php artisan migrate
```

---

### Step 4 — (Optional) Publish views &amp; assets

[](#step-4--optional-publish-views--assets)

```
# Customise the Blade views
php artisan vendor:publish --tag=audit-pro-views

# Publish static assets to public/vendor/audit-pro
php artisan vendor:publish --tag=audit-pro-assets
```

---

⚙️ Configuration
----------------

[](#️-configuration)

All options live in `config/audit-pro.php` (after publishing).

Key settings:

```
// Enable / disable globally
'enabled' => env('AUDIT_PRO_ENABLED', true),

// Separate DB connection (optional)
'connection' => env('AUDIT_PRO_CONNECTION', null),

// Models automatically observed (alternative to HasActivityLog trait)
'observe_models' => [
    \App\Models\User::class,
    \App\Models\Order::class,
],

// Events to track
'events' => ['created', 'updated', 'deleted', 'restored'],

// Fields NEVER included in diffs
'exclude_fields' => ['password', 'remember_token', 'updated_at', 'created_at'],

// Async queue logging
'queue' => [
    'enabled' => env('AUDIT_PRO_QUEUE', false),
    'name'    => env('AUDIT_PRO_QUEUE_NAME', 'audit-pro'),
],

// Admin panel route configuration
'routes' => [
    'enabled'    => true,
    'prefix'     => env('AUDIT_PRO_ROUTE_PREFIX', 'audit-pro'),
    'middleware' => ['web', 'auth'],
],

// Auto-delete logs older than N days (null = keep forever)
'retention_days' => env('AUDIT_PRO_RETENTION', null),
```

---

📖 Usage
-------

[](#-usage)

### Option A — `HasActivityLog` Trait (Per-model)

[](#option-a--hasactivitylog-trait-per-model)

Add the trait to any Eloquent model:

```
use Codersandip\AuditPro\Traits\HasActivityLog;

class Order extends Model
{
    use HasActivityLog;

    // Optional — exclude specific fields from diffs
    protected array $auditExclude = ['secret_token'];

    // Optional — only track these fields (whitelist)
    protected array $auditInclude = ['status', 'total', 'paid_at'];

    // Optional — custom log description
    public function getActivityLogDescription(string $event): ?string
    {
        return "Order #{$this->id} was {$event}";
    }
}
```

That's it! Every `create`, `update`, `delete`, and `restore` will be logged automatically.

---

### Option B — Global Observer (Config-based)

[](#option-b--global-observer-config-based)

Add models to `config/audit-pro.php` instead of adding the trait:

```
'observe_models' => [
    \App\Models\Product::class,
    \App\Models\User::class,
],
```

---

### Manual Logging

[](#manual-logging)

Use the `AuditPro` Facade or the `audit_log()` helper:

```
use Codersandip\AuditPro\Facades\AuditPro;

// Facade
AuditPro::log(
    event: 'payment',
    subject: $order,
    oldValues: ['status' => 'pending'],
    newValues: ['status' => 'paid'],
    description: 'Payment processed via Stripe',
    extra: ['stripe_charge_id' => 'ch_xxx'],
);

// Helper function
audit_log('exported', $report, description: 'Admin exported monthly report');
```

---

### Batch Logging

[](#batch-logging)

Group related events under one UUID for traceability:

```
audit_batch(function () use ($order, $invoice) {
    $order->update(['status' => 'paid']);
    $invoice->update(['paid_at' => now()]);
});
```

Or via Facade:

```
$batchId = AuditPro::startBatch();
$order->update(['status' => 'shipped']);
$shipment->create([...]);
AuditPro::endBatch();
```

---

### Skip Auditing Temporarily

[](#skip-auditing-temporarily)

```
// Single callback
Order::withoutAuditing(function () {
    Order::where('status', 'old')->update(['status' => 'archived']);
});

// Toggle manually
Order::disableAuditing();
// … bulk operations …
Order::enableAuditing();
```

---

### Retrieve Logs for a Model

[](#retrieve-logs-for-a-model)

```
// Via trait method
$logs = $order->activityLogs();

// Via helper
$logs = audit_logs_for($order);

// Via query scopes
use Codersandip\AuditPro\Models\ActivityLog;

ActivityLog::forSubject(Order::class, $orderId)
    ->event('updated')
    ->dateRange('2024-01-01', '2024-01-31')
    ->latest()
    ->get();
```

---

🖥️ Admin Panel
--------------

[](#️-admin-panel)

Visit the panel at:

```
http://yourdomain.test/audit-pro

```

Features:

- **Stat cards** — total, created, updated, deleted, today's count
- **Filters** — search, model, event, user, date range
- **Paginated table** with before/after diff modal
- **CSV export** respecting active filters

### Protecting the Panel

[](#protecting-the-panel)

The panel uses the middleware configured in `audit-pro.routes.middleware` (default: `['web', 'auth']`).

To require a specific role/permission, update:

```
// config/audit-pro.php
'routes' => [
    'middleware' => ['web', 'auth', 'can:view-audit-logs'],
],
```

---

🔒 Disable Logging for Specific Routes
-------------------------------------

[](#-disable-logging-for-specific-routes)

Use the built-in middleware:

```
// routes/web.php
Route::middleware('audit-pro.disable')->group(function () {
    Route::post('/bulk-import', BulkImportController::class);
});
```

---

📤 Export
--------

[](#-export)

### Via Admin Panel UI

[](#via-admin-panel-ui)

Click the **Export CSV** button on the logs listing page. Active filters are included in the export.

### Via Artisan

[](#via-artisan)

```
# Export all logs
php artisan audit-pro:export

# Export last 7 days of deleted events
php artisan audit-pro:export --days=7 --event=deleted

# Custom output path
php artisan audit-pro:export --path=/var/backups/audit
```

---

🧹 Log Retention
---------------

[](#-log-retention)

```
# Delete logs older than config retention_days value
php artisan audit-pro:clean

# Override days at runtime
php artisan audit-pro:clean --days=30
```

Schedule in `app/Console/Kernel.php`:

```
$schedule->command('audit-pro:clean')->daily();
```

---

⚡ Queue Support
---------------

[](#-queue-support)

Enable in `.env`:

```
AUDIT_PRO_QUEUE=true
AUDIT_PRO_QUEUE_NAME=audit-pro

```

Make sure a queue worker is running:

```
php artisan queue:work --queue=audit-pro
```

---

🧪 Testing
---------

[](#-testing)

```
composer test
# or
vendor/bin/phpunit
```

---

🗂️ Folder Structure
-------------------

[](#️-folder-structure)

```
laravel-audit-pro/
├── composer.json
├── phpunit.xml
├── config/
│   └── audit-pro.php
├── database/
│   └── migrations/
│       └── 2024_01_01_000001_create_activity_logs_table.php
├── resources/
│   └── views/
│       ├── layouts/
│       │   └── app.blade.php
│       ├── index.blade.php
│       └── partials/
│           └── detail.blade.php
├── routes/
│   └── web.php
├── src/
│   ├── AuditLogger.php
│   ├── AuditProServiceProvider.php
│   ├── helpers.php
│   ├── Console/Commands/
│   │   ├── CleanLogsCommand.php
│   │   └── ExportLogsCommand.php
│   ├── Facades/
│   │   └── AuditPro.php
│   ├── Http/
│   │   ├── Controllers/
│   │   │   └── ActivityLogController.php
│   │   └── Middleware/
│   │       ├── AuditProAuth.php
│   │       └── DisableLogging.php
│   ├── Jobs/
│   │   └── LogActivityJob.php
│   ├── Models/
│   │   └── ActivityLog.php
│   ├── Observers/
│   │   └── ActivityObserver.php
│   ├── Services/
│   │   └── ExportService.php
│   └── Traits/
│       └── HasActivityLog.php
└── tests/
    ├── TestCase.php
    ├── Feature/
    │   └── ActivityLoggingTest.php
    └── Fixtures/
        └── DummyModel.php

```

---

🚢 Publishing to Packagist
-------------------------

[](#-publishing-to-packagist)

1. Push code to GitHub: `git push origin main`
2. Tag a release: `git tag v1.0.0 && git push --tags`
3. Submit at [packagist.org/packages/submit](https://packagist.org/packages/submit)
4. Enable GitHub webhook for auto-updates

### Versioning Strategy

[](#versioning-strategy)

VersionTypeExample`1.0.0`Initial stable releaseFirst Packagist submit`1.0.x`Bug fixes`1.0.1`, `1.0.2``1.x.0`New features (backward-compat)`1.1.0``2.0.0`Breaking changesMajor Laravel support bump---

💰 Monetisation / Pro SaaS Ideas
-------------------------------

[](#-monetisation--pro-saas-ideas)

FeatureTierOpen-source core on GitHub/Packagist**Free**Real-time WebSocket log feed**Pro**Anomaly detection &amp; alerts (email/Slack)**Pro**Custom dashboards &amp; charts (Chart.js)**Pro**Multi-tenant SaaS with subdomain isolation**Enterprise**Retention policies &amp; GDPR export tools**Enterprise**REST API for logs (audit log as a service)**Enterprise**White-label &amp; branding customisation**Agency**---

📄 License
---------

[](#-license)

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

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance87

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

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

Unknown

Total

1

Last Release

64d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/156ff476b46c2fdcf56b1ea2dd94a891f78c538b1e8243774219ff08a81aa236?d=identicon)[codersandip](/maintainers/codersandip)

---

Top Contributors

[![tushar-sandip](https://avatars.githubusercontent.com/u/99278791?v=4)](https://github.com/tushar-sandip "tushar-sandip (1 commits)")

---

Tags

laravelloggingAuditobserveradminactivity-log

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codersandip-laravel-audit-pro/health.svg)

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

###  Alternatives

[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[shaffe/laravel-mail-log-channel

A package to support logging via email in Laravel

1286.2k](/packages/shaffe-laravel-mail-log-channel)

PHPackages © 2026

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