PHPackages                             umairhanifdev/laravel-table-logger - 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. umairhanifdev/laravel-table-logger

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

umairhanifdev/laravel-table-logger
==================================

Automated Laravel model auditing and application log management with dynamic table creation. Tracks all model changes (create/update/delete) in dedicated log tables while maintaining native Laravel conventions. Provides comprehensive activity monitoring without database modifications.

2.0.2(10mo ago)06MITPHPPHP &gt;=7.4

Since Jun 22Pushed 10mo agoCompare

[ Source](https://github.com/umairhanifdev/laravel-table-logger)[ Packagist](https://packagist.org/packages/umairhanifdev/laravel-table-logger)[ RSS](/packages/umairhanifdev-laravel-table-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Laravel Table Logger
====================

[](#laravel-table-logger)

A Laravel package to automatically or manually log model events (create, update, delete) either to the database or file system, based on `.env` configuration.

---

🚀 Features
----------

[](#-features)

- 🔁 Automatically logs `create`, `update`, `delete` actions on models
- ⚙️ Supports both database and file logging via `.env`
- 🧠 Easily retrieve logs using model relationships
- 🔧 Manually log any action without relying on model events
- 📁 Structured file-based logs per table and record
- 📦 Simple to integrate via Eloquent traits

---

📦 Installation
--------------

[](#-installation)

```
composer  require  umairhanifdev/laravel-table-logger
```

---

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

[](#️-configuration)

Publish config (optional):

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

Set logging driver in your `.env`:

```
TABLE_LOGGER_DRIVER=database # or "file"
```

- **database**: Logs are stored in `{table_name}_logs` tables
- **file**: Logs are stored in `storage/logs/umairhanifdev/{table}/{id}.log`

---

📘 Usage
-------

[](#-usage)

### 1. Eloquent Model Logging

[](#1-eloquent-model-logging)

#### Step 1: Add Traits

[](#step-1-add-traits)

Add the following traits to your Eloquent model. Once added, logs will automatically be generated on `create`, `update`, and `delete` actions.

```
use UmairHanif\LaravelTableLogger\Traits\Loggable;

use UmairHanif\LaravelTableLogger\Traits\HasLogs;

class  ExaminationReport  extends  Model

{

use  Loggable, HasLogs;

}
```

---

### 2. Retrieve Stored Logs

[](#2-retrieve-stored-logs)

#### Logs for a Single Model Record

[](#logs-for-a-single-model-record)

```
$report = ExaminationReport::find($id);

$reportLogs = $report->logs()->get();
```

#### Logs for Multiple Records

[](#logs-for-multiple-records)

```
$examReports = ExaminationReport::where('user_id', 16)->get();

$examinationLogs = $examReports->logsBatch()

->where('this_log_action', 'update') // optional filter

->get();
```

---

### 3. Manual Logging (No Eloquent Required)

[](#3-manual-logging-no-eloquent-required)

You can manually log an action without triggering Eloquent events:

```
use UmairHanif\LaravelTableLogger\Helpers\LoggerLog;

LoggerLog::logAction('examination_reports', $id, 'delete');

DB::table('examination_reports')->where('id', $id)->delete();
```

---

### 4. Nested Logs via Relationships

[](#4-nested-logs-via-relationships)

If your model (e.g., `User`) has child models using logs (e.g., `ExaminationReport`), you can retrieve logs as:

```
$user = User::with(['examination' => function ($q) {

$q->whereStatus(1)->orderBy('id', 'DESC');

}])->find($id);

// Logs for the parent model (User)

$usersLogs = $user->logs()->get();

// Logs for nested model (Examinations)

$examinationLogs = collect();

if ($user->examination) {

$examinationLogs = $user->examination->logsBatch()

->where('this_log_action', 'update') //optional - to filter the logs futher

->get();

}
```

---

🗃️ Log Table Naming Convention
------------------------------

[](#️-log-table-naming-convention)

Log tables are automatically named using the singular form of the model table name + `_logs`. Example: `users` → `user_logs`

You can define custom mappings for irregular plurals:

```
'irregular_plurals' => [

'people' => 'person',

'children' => 'child',

'men' => 'man',

'women' => 'woman',

],
```

---

📂 File-based Log Format
-----------------------

[](#-file-based-log-format)

When using `TABLE_LOGGER_DRIVER=file`, logs are saved as JSON files in:

```

storage/logs/umairhanifdev/{table}/{id}.log

```

Each file will contain all logs of a specific record.

---

📝 License
---------

[](#-license)

MIT

---

Built with ❤️ by Umair Hanif

🌐 [umairhanif.com](https://umairhanif.com)

📫

🔗 [LinkedIn](https://www.linkedin.com/in/umair-hanif-a95179155/)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance53

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

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

2

Last Release

324d ago

### Community

Maintainers

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

---

Top Contributors

[![umairhanifdev](https://avatars.githubusercontent.com/u/62742027?v=4)](https://github.com/umairhanifdev "umairhanifdev (21 commits)")

### Embed Badge

![Health badge](/badges/umairhanifdev-laravel-table-logger/health.svg)

```
[![Health](https://phpackages.com/badges/umairhanifdev-laravel-table-logger/health.svg)](https://phpackages.com/packages/umairhanifdev-laravel-table-logger)
```

###  Alternatives

[overtrue/laravel-query-logger

A dev tool to log all queries for laravel application.

413307.5k6](/packages/overtrue-laravel-query-logger)[guanguans/laravel-exception-notify

Monitor exception and report to the notification channels(Log、Mail、AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

14642.7k1](/packages/guanguans-laravel-exception-notify)[regulus/activity-log

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

164220.1k2](/packages/regulus-activity-log)

PHPackages © 2026

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