PHPackages                             jimoh/laravel-activity-feed - 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. jimoh/laravel-activity-feed

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

jimoh/laravel-activity-feed
===========================

A Laravel package for logging model events and manual activity to an activity log table.

v1.0.0(1mo ago)10MITPHPPHP ^8.2CI passing

Since Jun 1Pushed 1mo agoCompare

[ Source](https://github.com/Tsdjimmy/laravel-activity-feed)[ Packagist](https://packagist.org/packages/jimoh/laravel-activity-feed)[ RSS](/packages/jimoh-laravel-activity-feed/feed)WikiDiscussions main Synced 1w ago

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

laravel-activity-feed
=====================

[](#laravel-activity-feed)

[![Tests](https://github.com/tsdjimmy/laravel-activity-feed/actions/workflows/tests.yml/badge.svg)](https://github.com/tsdjimmy/laravel-activity-feed/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/ad566bebee1b7b687e5c2a4dfc08c59c2e24db592f7ad1073e0e0ee26da41491/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a696d6f682f6c61726176656c2d61637469766974792d666565642e737667)](https://packagist.org/packages/jimoh/laravel-activity-feed)[![PHP Version](https://camo.githubusercontent.com/daaff0775d1f4b18fccb6829601770326e98171e4679e1013a3f507f982bbd2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a696d6f682f6c61726176656c2d61637469766974792d666565642e737667)](https://packagist.org/packages/jimoh/laravel-activity-feed)[![Laravel](https://camo.githubusercontent.com/d9ee4708df76c3020e1cfe806419871e9ab3ad3b2b4e9ea1b8b0e6d37f5c4402/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d3131253230253743253230313225323025374325323031332d4646324432303f6c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://laravel.com)[![License](https://camo.githubusercontent.com/3b0ac717e07a6315394b9565fe2cc5d35ea67394a68d1628b7531f1a0e0a28a1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a696d6f682f6c61726176656c2d61637469766974792d666565642e737667)](LICENSE)

A Laravel package that logs model events and manual activity to an `activity_log` table. Includes a fluent query builder, model-change diff viewer, optional queue driver, intelligent caching, and an optional Filament v3 panel plugin (coming soon).

---

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

[](#requirements)

- PHP 8.2+
- Laravel 11+

---

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

[](#installation)

```
composer require jimoh/laravel-activity-feed
```

Publish and run the migration:

```
php artisan vendor:publish --tag=activity-feed-migrations
php artisan migrate
```

Optionally publish the config:

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

---

Database schema
---------------

[](#database-schema)

```
┌─────────────────────────────────────────────────────────────┐
│                        activity_log                         │
├──────────────────┬──────────────────────────────────────────┤
│ id               │ bigint, primary key                      │
│ log_name         │ string  default:'default'  ← index       │
│ description      │ string                                   │
│ subject_type     │ string, nullable  ┐                      │
│ subject_id       │ bigint, nullable  ┘← morphs index        │
│ subject_snapshot │ json, nullable                           │
│ causer_type      │ string, nullable  ┐                      │
│ causer_id        │ bigint, nullable  ┘← morphs index        │
│ properties       │ json, nullable  (old/new diff goes here) │
│ event            │ string, nullable                         │
│ ip_address       │ string(45), nullable                     │
│ user_agent       │ string(1024), nullable                   │
│ tags             │ json, nullable                           │
│ created_at       │ timestamp  ← index (pruning + scopes)    │
│ updated_at       │ timestamp                                │
└──────────────────┴──────────────────────────────────────────┘

```

---

Write flow
----------

[](#write-flow)

```
activity()->log('...')
        │
        ▼
  queue enabled?
   ┌────┴────┐
  YES       NO
   │         │
   ▼         ▼
WriteActivityLog    ActivityLogger::writeToDb()
  job dispatched         │
  (3 retries,            ▼
   10s backoff)    activity_log table
        │
        ▼  (on job handle)
  ActivityLogger::writeToDb()
        │
        ▼
  activity_log table

After every write (inline or queued dispatch):
  ActivityCacher::forget($subject)  ←── cache invalidated

```

---

Basic usage
-----------

[](#basic-usage)

### Automatic model logging (trait)

[](#automatic-model-logging-trait)

Add the `LogsActivity` trait to any Eloquent model. It will automatically log `created`, `updated`, and `deleted` events, including a before/after diff on updates.

```
use Jimoh\ActivityFeed\Traits\LogsActivity;

class Invoice extends Model
{
    use LogsActivity;

    // Optional: whitelist — only these fields appear in diffs
    protected array $logAttributes = ['status', 'amount'];

    // Optional: blacklist — never appear in diffs
    protected array $ignoreAttributes = ['internal_notes'];
}
```

### Manual activity logging

[](#manual-activity-logging)

Use the `activity()` helper or the `Activity` facade:

```
activity()
    ->performedOn($invoice)
    ->causedBy($user)
    ->withProperties(['amount' => 1500])
    ->withTag('billing')
    ->inLog('admin_audit')
    ->log('approved invoice');
```

```
use Jimoh\ActivityFeed\Facades\Activity;

Activity::performedOn($invoice)->causedBy($user)->log('sent reminder');
```

---

Querying the feed
-----------------

[](#querying-the-feed)

```
use Jimoh\ActivityFeed\Models\Activity;

// All activity for a model
Activity::forSubject($invoice)->get();

// All activity caused by a user
Activity::causedBy($user)->get();

// Filter by log name
Activity::inLog('admin_audit')->get();

// Filter by tag
Activity::withTag('billing')->get();

// Time scopes
Activity::today()->get();
Activity::thisWeek()->get();

// Chainable
Activity::forSubject($invoice)->inLog('admin_audit')->latest()->paginate(25);
```

---

Viewing diffs
-------------

[](#viewing-diffs)

```
$activity = Activity::forSubject($invoice)->where('event', 'updated')->first();

$diff = $activity->getDiff();
// [
//   'status' => ['old' => 'pending', 'new' => 'approved'],
//   'amount' => ['old' => 1000,      'new' => 1500],
// ]
```

---

Config reference
----------------

[](#config-reference)

Publish with `php artisan vendor:publish --tag=activity-feed-config`.

KeyDefaultEnv varDescription`default_log_name``"default"`—Default value for `log_name``model``Activity::class`—Eloquent model class for the log table`queue``false`—Enable async writing via queue`queue_connection``"default"``ACTIVITY_QUEUE_CONNECTION`Queue connection name`queue_name``"default"``ACTIVITY_QUEUE_NAME`Queue name`cache``false`—Enable feed caching`cache_store``null``ACTIVITY_CACHE_STORE`Cache store (null = app default)`cache_ttl``300``ACTIVITY_CACHE_TTL`Cache TTL in seconds`prune_days``90`—Days to retain logs (used by `activity:prune`)`capture_snapshot``false`—Store full model snapshot on each event`capture_ip``true`—Capture IP address from the request`capture_user_agent``true`—Capture User-Agent from the request`subject_returns_soft_deleted``true`—Include soft-deleted subjects in relations---

Pruning old records
-------------------

[](#pruning-old-records)

```
php artisan activity:prune          # uses prune_days from config
php artisan activity:prune --days=30
```

Records are deleted in chunks of 1 000 to avoid locking the table.

---

High-traffic setup
------------------

[](#high-traffic-setup)

For applications with heavy write traffic, enable the queue driver and add a Redis cache to reduce database pressure.

### `.env`

[](#env)

```
ACTIVITY_QUEUE_CONNECTION=redis
ACTIVITY_QUEUE_NAME=activity

ACTIVITY_CACHE_STORE=redis
ACTIVITY_CACHE_TTL=600
```

### `config/activity-feed.php`

[](#configactivity-feedphp)

```
'queue' => true,
'cache' => true,
```

### Supervisor worker

[](#supervisor-worker)

```
[program:activity-worker]
command=php /var/www/artisan queue:work redis --queue=activity --tries=3
autostart=true
autorestart=true
```

When `queue = true`, `activity()->log()` dispatches a `WriteActivityLog` job (3 retries, 10 s backoff) instead of writing inline. When `cache = true`, `forSubject()` and `causedBy()` results are cached per page. Cache invalidation is automatic on every new write; manual invalidation is also available:

```
use Jimoh\ActivityFeed\Cachers\ActivityCacher;

app(ActivityCacher::class)->forget($invoice);
```

Drivers that support cache tags (Redis, Memcached) use tag-based invalidation. File and database drivers fall back to a key registry.

---

Filament v3 plugin
------------------

[](#filament-v3-plugin)

Coming soon.

---

Author
------

[](#author)

**Oluwasegun Jimoh** — [github.com/tsdjimmy](https://github.com/tsdjimmy) —

---

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance89

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

53d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25033301?v=4)[Oluwasegun Jimoh](/maintainers/tsdjimmy)[@Tsdjimmy](https://github.com/Tsdjimmy)

---

Top Contributors

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

---

Tags

loglaravelfeedactivityAudit

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/jimoh-laravel-activity-feed/health.svg)

```
[![Health](https://phpackages.com/badges/jimoh-laravel-activity-feed/health.svg)](https://phpackages.com/packages/jimoh-laravel-activity-feed)
```

###  Alternatives

[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M136](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M133](/packages/roots-acorn)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k96.5k1](/packages/mike-bronner-laravel-model-caching)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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