PHPackages                             imamsudarajat04/laravel-change-logs - 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. [Database &amp; ORM](/categories/database)
4. /
5. imamsudarajat04/laravel-change-logs

ActiveLibrary[Database &amp; ORM](/categories/database)

imamsudarajat04/laravel-change-logs
===================================

A comprehensive change logs tracking package for Laravel 11+ that automatically tracks all model changes (create, update, delete, restore) with detailed audit trails

v1.2.2(5mo ago)216MITPHPPHP ^8.2|^8.3|^8.4

Since Dec 6Pushed 5mo agoCompare

[ Source](https://github.com/imamsudarajat04/change-logs)[ Packagist](https://packagist.org/packages/imamsudarajat04/laravel-change-logs)[ Docs](https://github.com/imamsudarajat04/laravel-change-logs)[ RSS](/packages/imamsudarajat04-laravel-change-logs/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (13)Used By (0)

Laravel Change Logs
===================

[](#laravel-change-logs)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2e239ff19de1da9ffa4b6585ebad365235bf03c3fac4f3a886f6ce2847dbbeca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d616d7375646172616a617430342f6c61726176656c2d6368616e67652d6c6f67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/imamsudarajat04/laravel-change-logs)[![Total Downloads](https://camo.githubusercontent.com/8196631693f598873b2da381620f0c574dc1b71190c4791993f475df06255648/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696d616d7375646172616a617430342f6c61726176656c2d6368616e67652d6c6f67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/imamsudarajat04/laravel-change-logs)

A comprehensive change logs tracking package for Laravel 11+ that automatically tracks all model changes (create, update, delete, restore) with detailed audit trails.

Features
--------

[](#features)

✨ **Automatic Tracking** - Zero configuration needed, just add a trait 📝 **Detailed Logging** - Track field-level changes with old/new values 🔍 **Flexible Querying** - Built-in scopes and filters 👤 **User Context** - Automatically captures user, IP, and user agent 🏷️ **Tagging Support** - Categorize logs with custom tags ⚡ **Queue Support** - Async logging for better performance 🧹 **Auto Cleanup** - Scheduled cleanup of old logs 🎯 **Polymorphic** - Works with any Eloquent model 🔒 **Security** - Excludes sensitive fields (passwords, tokens) 📊 **Statistics** - Built-in analytics and reporting

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

[](#requirements)

- PHP 8.2+
- Laravel 11.0+
- MySQL / PostgreSQL / SQLite

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

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require imamsudarajat04/laravel-change-logs
```

### 2. Install Package

[](#2-install-package)

```
php artisan vendor:publish --provider="Imamsudarajat04\\ChangeLogs\\ChangeLogsServiceProvider"
```

This will publish:

- Configuration file: `config/change-logs.php`
- Migration file: `database/migrations/xxx_create_change_logs_table.php`

### 3. Run Migrations

[](#3-run-migrations)

```
php artisan migrate
```

Basic Usage
-----------

[](#basic-usage)

### Add Trait to Model

[](#add-trait-to-model)

```
use Imamsudarajat04\ChangeLogs\Traits\HasChangeLogs;

class User extends Authenticatable
{
    use HasChangeLogs;
}
```

That's it! Now all changes to `User` model will be automatically tracked.

### Access Change Logs

[](#access-change-logs)

```
// Get all change logs for a model
$user = User::find(1);
$logs = $user->changeLogs; // Returns collection of ChangeLog

// Get recent logs
$recentLogs = $user->recentChangeLogs(5);

// Get logs by action
$updateLogs = $user->changeLogsByAction('UPDATE');

// Get logs for specific field
$emailChanges = $user->fieldChangeLogs('email');

// Check if model has logs
if ($user->hasChangeLogs()) {
    // ...
}

// Get last change
$lastChange = $user->lastChangeLog();
```

### Query Change Logs Directly

[](#query-change-logs-directly)

```
use Imamsudarajat04\ChangeLogs\Models\ChangeLog;

// Using scopes
$logs = ChangeLog::action('UPDATE')->get();
$logs = ChangeLog::forModel(User::class)->byUser(1)->get();
$logs = ChangeLog::dateRange('2024-01-01', '2024-12-31')->get();
$logs = ChangeLog::withTag('important')->get();

// Chain multiple scopes
$logs = ChangeLog::action('UPDATE')
    ->byUser(1)
    ->dateRange('2024-01-01', '2024-12-31')
    ->limit(10)
    ->get();
```

### Using Service/Facade

[](#using-servicefacade)

```
use Imamsudarajat04\ChangeLogs\Facades\ChangeLog;

// Query with filters
$logs = ChangeLog::query([
    'action' => 'UPDATE',
    'user_id' => 1,
    'start_date' => '2024-01-01',
    'end_date' => '2024-12-31',
])->paginate(20);

// Get statistics
$stats = ChangeLog::getStatistics();
// Returns: ['total' => 100, 'by_action' => [...], 'by_user' => [...], 'recent' => [...]]

// Cleanup old logs
ChangeLog::cleanup(365); // Delete logs older than 365 days
```

Advanced Usage
--------------

[](#advanced-usage)

### Customize Excluded Fields

[](#customize-excluded-fields)

```
class User extends Authenticatable
{
    use HasChangeLogs;

    public function getChangeLogExcludedFields(): array
    {
        return ['password', 'remember_token', 'api_token'];
    }
}
```

### Custom Descriptions

[](#custom-descriptions)

```
class User extends Authenticatable
{
    use HasChangeLogs;

    public function getChangeLogDescription(string $action): ?string
    {
        return match($action) {
            'CREATE' => "User {$this->name} was registered",
            'UPDATE' => "User {$this->name} updated their profile",
            'DELETE' => "User {$this->name} was deleted",
            default => null,
        };
    }
}
```

### Custom Tags

[](#custom-tags)

```
class Order extends Model
{
    use HasChangeLogs;

    public function getChangeLogTags(string $action): array
    {
        return match($action) {
            'CREATE' => ['order', 'new', 'customer-action'],
            'UPDATE' => ['order', 'modified'],
            default => ['order'],
        };
    }
}
```

### Conditional Logging

[](#conditional-logging)

```
class User extends Authenticatable
{
    use HasChangeLogs;

    public function shouldLogChanges(string $action): bool
    {
        // Don't log test users
        if (str_contains($this->email, '@test.com')) {
            return false;
        }

        return parent::shouldLogChanges($action);
    }
}
```

### Temporarily Disable Logging

[](#temporarily-disable-logging)

```
// For single model
User::withoutChangeLogs(function() {
    User::where('active', 0)->update(['status' => 'inactive']);
});

// For specific operations
config(['change-logs.enabled' => false]);
// Your operations here
config(['change-logs.enabled' => true]);
```

Artisan Commands
----------------

[](#artisan-commands)

### Install Package

[](#install-package)

```
php artisan change-logs:install

# Options:
--migrations    # Only publish migrations
--config       # Only publish config
--force        # Overwrite existing files
```

### View Statistics

[](#view-statistics)

```
php artisan change-logs:stats

# With filters:
php artisan change-logs:stats --user=1
php artisan change-logs:stats --action=UPDATE
php artisan change-logs:stats --model="App\Models\User"
php artisan change-logs:stats --days=7
```

### Cleanup Old Logs

[](#cleanup-old-logs)

```
php artisan change-logs:cleanup

# Options:
--days=90     # Custom retention days
--force       # Skip confirmation
```

### Prune with Filters

[](#prune-with-filters)

```
php artisan change-logs:prune

# Options:
--model="App\Models\User"  # Prune specific model
--action=DELETE            # Prune specific action
--pretend                  # Dry run
```

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

[](#configuration)

Publish and edit `config/change-logs.php`:

```
return [
    // Enable/disable globally
    'enabled' => env('CHANGE_LOGS_ENABLED', true),

    // Logging strategy
    'log_per_field' => false, // true = separate log per field, false = bulk

    // Track additional context
    'track_ip' => true,
    'track_user_agent' => true,

    // Exclude fields
    'hidden_fields' => ['password', 'remember_token'],
    'exclude_timestamps' => true,

    // Queue configuration
    'queue' => [
        'enabled' => false,
        'connection' => null,
        'queue' => 'default',
    ],

    // Auto cleanup
    'cleanup' => [
        'enabled' => false,
        'days' => 365,
    ],
];
```

Task Scheduling
---------------

[](#task-scheduling)

Add to `app/Console/Kernel.php`:

```
protected function schedule(Schedule $schedule)
{
    // Cleanup logs monthly
    $schedule->command('change-logs:cleanup --force')->monthly();

    // Or use prune
    $schedule->command('change-logs:prune')->monthly();
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

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

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Imam Sudarajat](https://github.com/imamsudarajat04)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance72

Regular maintenance activity

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity59

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

12

Last Release

156d ago

PHP version history (2 changes)v1.0.0PHP ^8.2

v1.0.1PHP ^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/f77fa611d114a61d880b65348e0f07d24c3b485d684239369cc600b2e14958ed?d=identicon)[imamsudarajat04](/maintainers/imamsudarajat04)

---

Top Contributors

[![imamsudarajat04](https://avatars.githubusercontent.com/u/70099731?v=4)](https://github.com/imamsudarajat04 "imamsudarajat04 (14 commits)")

---

Tags

laravellaravel 11eloquenttrackingAudithistoryaudit-trailactivity-logmodel-trackingchange-logs

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/imamsudarajat04-laravel-change-logs/health.svg)

```
[![Health](https://phpackages.com/badges/imamsudarajat04-laravel-change-logs/health.svg)](https://phpackages.com/packages/imamsudarajat04-laravel-change-logs)
```

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[altek/accountant

The auditing &amp; accountability package for Laravel's Eloquent ORM.

92954.3k4](/packages/altek-accountant)[baril/bonsai

An implementation of the Closure Tables pattern for Eloquent.

3593.5k](/packages/baril-bonsai)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[betapeak/laravel-auditing-filesystem

A filesystem driver for the owen-it/laravel-auditing package. Allows storage of the audits in CSV files, across all registered Laravel disks.

166.5k](/packages/betapeak-laravel-auditing-filesystem)

PHPackages © 2026

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