PHPackages                             foxen/laravel-model-activity-log - 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. foxen/laravel-model-activity-log

ActiveLaravel-package

foxen/laravel-model-activity-log
================================

A simple Laravel package to log model activity.

v1.0.0(1mo ago)00MITPHPPHP ^8.3CI passing

Since Mar 14Pushed 1mo agoCompare

[ Source](https://github.com/foxen-digital/laravel-model-activity-log)[ Packagist](https://packagist.org/packages/foxen/laravel-model-activity-log)[ GitHub Sponsors](https://github.com/foxen)[ RSS](/packages/foxen-laravel-model-activity-log/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

Laravel Model Activity Log
==========================

[](#laravel-model-activity-log)

A simple Laravel package to automatically record basic activity (creation, updates with attribute changes, deletion, restoration) performed on specified Eloquent models, and provide a mechanism for automatically pruning old log entries.

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

[](#installation)

You can install the package via composer:

```
composer require foxen/laravel-model-activity-log
```

The package will automatically register its service provider.

To publish the configuration file, run the following command:

```
php artisan vendor:publish --provider="Foxen\LaravelModelActivityLog\Providers\ActivityLogServiceProvider" --tag="config"
```

This will create a `foxen_activitylog.php` file in your `config` directory, which can be modified as required.

Finally, you need to run the migrations to create the `activity_log` table:

```
php artisan migrate
```

Usage
-----

[](#usage)

To enable activity logging for a model, simply use the `LogsActivity` trait in your model class:

```
use Illuminate\Database\Eloquent\Model;
use Foxen\LaravelModelActivityLog\Traits\LogsActivity;

class Post extends Model
{
    use LogsActivity;

    // ...
}
```

The following events are automatically logged: `created`, `updated`, `deleted`. If your model uses `SoftDeletes`, the `restored` event is logged as well.

When an action is performed by an authenticated user, they are recorded as the causer. Actions performed without an authenticated user (e.g. from a console command or queue job) are attributed to `System`.

### Customizing the Log Name

[](#customizing-the-log-name)

By default, the log name is set to `default`. You can customize this on a per-model basis by adding a `protected $activityLogName` property to your model:

```
class Post extends Model
{
    use LogsActivity;

    protected $activityLogName = 'posts';

    // ...
}
```

### Ignoring Attributes

[](#ignoring-attributes)

To exclude certain attributes from the activity log when a model is created or updated, you can add a `protected $ignoreActivityLogAttributes` property to your model:

```
class Post extends Model
{
    use LogsActivity;

    protected $ignoreActivityLogAttributes = ['updated_at'];

    // ...
}
```

### Redacting Attributes

[](#redacting-attributes)

To redact sensitive attributes from the activity log, you can add a `protected $redactedActivityLogAttributes` property to your model. The attribute key will be logged, but the value will be replaced with `[REDACTED]`.

```
class User extends Model
{
    use LogsActivity;

    protected $redactedActivityLogAttributes = ['password', 'remember_token'];

    // ...
}
```

You can also configure global redacted attributes in the `config/foxen_activitylog.php` file.

### Retrieving Logs

[](#retrieving-logs)

You can retrieve activity logs using the `Foxen\LaravelModelActivityLog\Models\Activity` model. The package provides several convenient query scopes:

```
use Foxen\LaravelModelActivityLog\Models\Activity;

// Get all activity for a specific model instance
$activities = Activity::whereSubject($post)->get();

// Get all activity for a specific model type
$activities = Activity::forSubjectType('App\Models\Post')->get();

// Get all activity caused by a specific user
$activities = Activity::whereCauser($user)->get();

// Get all activity for a specific causer type
$activities = Activity::forCauserType('App\Models\User')->get();

// Get all activity for a specific event
$activities = Activity::forEvent('created')->get();
```

You can access the subject and causer models directly via their relationships:

```
$activity = Activity::first();

$subject = $activity->subject; // The model that was acted upon
$causer  = $activity->causer;  // The user who performed the action, or null
```

For `updated` events, the `properties` field contains the old and new values of changed attributes:

```
$activity = Activity::forEvent('updated')->first();

$old = $activity->properties['old']; // ['title' => 'Old Title']
$new = $activity->properties['new']; // ['title' => 'New Title']
```

### Pruning Logs

[](#pruning-logs)

The package can automatically prune old activity log entries. To enable this, set the `prune_activity_log` option to `true` in your `config/foxen_activitylog.php` file and configure the `prune_older_than_days` option.

```
// config/foxen_activitylog.php

return [
    // ...
    'prune_activity_log' => true,
    'prune_older_than_days' => 30,
];
```

Once enabled, you must schedule the `model:prune` command in your application's `routes/console.php` file:

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('model:prune')->daily();
```

Testing
-------

[](#testing)

```
composer test
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance88

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.7% 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

59d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/478d77e4c9a68f8d044e31c52eaee8b58d33ff77ed30bc8a1767ca92496d6cae?d=identicon)[mrdth](/maintainers/mrdth)

---

Top Contributors

[![mrdth](https://avatars.githubusercontent.com/u/781215?v=4)](https://github.com/mrdth "mrdth (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/foxen-laravel-model-activity-log/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[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)
