PHPackages                             devdabour/laravel-loggable - 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. devdabour/laravel-loggable

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

devdabour/laravel-loggable
==========================

Enhanced activity logging for Laravel with metadata, relationships tracking, and size management

v1.0.6(9mo ago)06MITPHPPHP ^8.0

Since Jul 18Pushed 9mo agoCompare

[ Source](https://github.com/ahmedkamaldabour/laravel-loggable)[ Packagist](https://packagist.org/packages/devdabour/laravel-loggable)[ RSS](/packages/devdabour-laravel-loggable/feed)WikiDiscussions master Synced 1mo ago

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

Laravel Loggable
================

[](#laravel-loggable)

Enhanced activity logging for Laravel with metadata, relationships tracking, and size management.

Features
--------

[](#features)

- 🚀 Easy to implement activity logging
- 📝 Customizable attribute mapping
- 🔍 Metadata tracking (IP, User Agent)
- 🔗 Relationship logging
- 📊 Content size management
- 🎯 Selective attribute logging
- 💾 Efficient storage handling
- 🌐 Translatable fields support
- 📄 JSON field handling
- 🧩 Nested JSON structure support
- ✨ Automatic translatable field processing (v1.0.5+)
- 🛡️ Support for Laravel 8.x, 9.x, and 10.x

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

[](#installation)

You can install the package via composer:

```
composer require devdabour/laravel-loggable
```

The package will automatically register its service provider.

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

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="Devdabour\LaravelLoggable\Providers\LoggableServiceProvider"
```

This will create a `loggable.php` configuration file in your `config` directory.

Database Migration
------------------

[](#database-migration)

After installing the package, you need to run the migration to create the activity log table:

```
php artisan migrate
```

This will create the necessary database table for storing activity logs.

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

[](#basic-usage)

1. Add the Loggable trait to your model:

```
use Devdabour\LaravelLoggable\Traits\Loggable;

class Product extends Model
{
    use Loggable;

    protected static array $logAttributes = [
        'name' => 'Product Name',
        'price' => 'Price',
        'status' => 'Status',
    ];
}
```

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

[](#advanced-usage)

### Metadata Logging

[](#metadata-logging)

Enable metadata logging to track IP address, user agent, and custom data:

```
class Product extends Model
{
    use Loggable;

    // Enable metadata logging
    protected static $logMetadata = true;

    // Add custom metadata
    protected static $logAdditionalData = [
        'custom_field' => 'Custom Label',
        'department' => 'Department Name'
    ];
}
```

### Relationship Tracking

[](#relationship-tracking)

Track changes in related models:

```
class Product extends Model
{
    use Loggable;

    protected static $logRelationships = [
        'category' => ['id', 'name'],
        'tags' => ['id', 'name'],
        'manufacturer' => ['id', 'company_name']
    ];
}
```

### Translatable Fields Support

[](#translatable-fields-support)

If you're using Spatie's Translatable trait, Loggable will automatically handle translatable fields and log each language separately:

> **Note:** Starting from version 1.0.5, translatable fields are processed automatically without requiring any custom methods.

#### Solution 1: Using the Nested Array Format (Recommended)

[](#solution-1-using-the-nested-array-format-recommended)

The most reliable way to ensure all languages are logged is to use the nested array format for your `$logAttributes`:

```
use Devdabour\LaravelLoggable\Traits\Loggable;
use Spatie\Translatable\HasTranslations;

class Phase extends Model
{
    use HasFactory;
    use Loggable;
    use HasTranslations;

    public $translatable = ['name'];

    // Define language-specific labels in a nested structure
    protected static array $logAttributes = [
        'name' => [
            'en' => 'English Name',
            'ar' => 'Arabic Name',
        ],
    ];
}
```

This ensures that each language translation is logged separately, regardless of the current application locale.

#### Solution 2: Explicitly Define JSON Fields

[](#solution-2-explicitly-define-json-fields)

You can also explicitly declare your translatable fields as JSON fields:

```
protected static array $jsonFields = ['name', 'description'];

protected static array $logAttributes = [
    'name_en' => 'English Name',
    'name_ar' => 'Arabic Name',
];
```

#### Solution 3: No Configuration Needed (v1.0.5+)

[](#solution-3-no-configuration-needed-v105)

With version 1.0.5 and above, translatable fields are automatically processed without requiring any custom methods:

```
use Devdabour\LaravelLoggable\Traits\Loggable;
use Spatie\Translatable\HasTranslations;

class Phase extends Model
{
    use HasFactory;
    use Loggable;
    use HasTranslations;

    public $translatable = ['name'];

    // That's it! All languages will be logged automatically
    // Each language will appear as "name (en)", "name (ar)", etc.
}
```

If you do need custom processing, you can still implement a `modelCustomTapActivity` method which will be called after the automatic processing.

### JSON Field Handling

[](#json-field-handling)

Loggable now supports any JSON column, not just translatable fields:

```
class UserSettings extends Model
{
    use Loggable;

    protected $casts = [
        'preferences' => 'json',
        'notifications' => 'json',
    ];

    // Tell Loggable which fields contain JSON data
    protected static array $jsonFields = ['preferences', 'notifications'];

    // Optional: Map specific JSON paths to readable labels
    protected static array $logAttributes = [
        'preferences' => [
            'theme' => 'UI Theme',
            'language' => 'Display Language',
        ],
        'notifications.email' => 'Email Notifications',
        'notifications.push' => 'Push Notifications',
    ];
}
```

### Nested JSON Structures

[](#nested-json-structures)

For complex nested JSON data, Loggable automatically flattens the structure using dot notation:

```
// Database JSON: {"settings":{"theme":"dark","notifications":{"email":true,"push":false}}}

// Activity log will show:
// settings.theme: dark
// settings.notifications.email: true
// settings.notifications.push: false
```

You can provide custom labels for nested paths:

```
protected static array $logAttributes = [
    'settings.theme' => 'Theme Setting',
    'settings.notifications.email' => 'Email Notifications',
];
```

Utility Methods
---------------

[](#utility-methods)

The package provides several utility methods:

```
// Check if a string is valid JSON
$model->isJson($string);

// Get human-readable attributes
$attributes = $model->getLogAttributes();

// Get custom log name
$logName = $model->getLogName();
```

Changelog
---------

[](#changelog)

### 1.0.5 (2025-07-18)

[](#105-2025-07-18)

- Added automatic processing of translatable fields
- Fixed issues with modelCustomTapActivity method
- Improved handling of translatable fields across multiple languages

### 1.0.4 (2025-07-18)

[](#104-2025-07-18)

- Made isJson method public for better utility access
- Fixed accessibility issues with helper methods

### 1.0.3 (2025-07-18)

[](#103-2025-07-18)

- Added support for JSON field handling
- Added nested JSON structure support
- Enhanced mapping for complex data structures

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance59

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

6

Last Release

294d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/802e9da46d7fad15a47e55069d4211899714fe310c94f2a6988b73d56d89e067?d=identicon)[ahmedkamaldabour](/maintainers/ahmedkamaldabour)

---

Top Contributors

[![ahmedkamaldabour](https://avatars.githubusercontent.com/u/61318414?v=4)](https://github.com/ahmedkamaldabour "ahmedkamaldabour (6 commits)")

---

Tags

laravelloggingaudit-trailactivity-trackingactivity-logmodel-changes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/devdabour-laravel-loggable/health.svg)

```
[![Health](https://phpackages.com/badges/devdabour-laravel-loggable/health.svg)](https://phpackages.com/packages/devdabour-laravel-loggable)
```

###  Alternatives

[rollbar/rollbar-laravel

Rollbar error monitoring integration for Laravel projects

14110.4M7](/packages/rollbar-rollbar-laravel)[muhammadsadeeq/laravel-activitylog-ui

A beautiful, modern UI for Spatie's Activity Log with advanced filtering, analytics, and real-time features.

17510.1k](/packages/muhammadsadeeq-laravel-activitylog-ui)[alizharb/filament-activity-log

A powerful, feature-rich activity logging solution for FilamentPHP v4 &amp; v5 with timeline views, dashboard widgets, and revert actions.

2326.6k](/packages/alizharb-filament-activity-log)[noxoua/filament-activity-log

A Laravel package that simplifies activity logging in the Filament admin panel, with support for logging create, update, delete, and restore actions. It integrates with the 'spatie/laravel-activitylog' package and includes a modernized activity log viewing page.

7151.5k](/packages/noxoua-filament-activity-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)
