PHPackages                             shkiper/laravel-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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. shkiper/laravel-activity-log

ActiveLaravel-package[Logging &amp; Monitoring](/categories/logging)

shkiper/laravel-activity-log
============================

Activity logging package for Laravel 12 applications

1.0.1(1y ago)116MITPHPPHP ^8.2CI passing

Since Oct 29Pushed 9mo ago1 watchersCompare

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

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

[![PHP Tests](https://github.com/shkiper/laravel-activity-log/actions/workflows/php-tests.yml/badge.svg)](https://github.com/shkiper/laravel-activity-log/actions/workflows/php-tests.yml)[![codecov](https://camo.githubusercontent.com/c82dddc63e4009517457346b4f9a948fe48c57f6454896aad462fec0e9e1b95b/68747470733a2f2f636f6465636f762e696f2f67682f73686b697065722f6c61726176656c2d61637469766974792d6c6f672f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/shkiper/laravel-activity-log)

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

[](#laravel-activity-log)

A package for logging actions and changes in models for Laravel 12. Developed with support for different data stores and Laravel 12.

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

[](#installation)

```
composer require shkiper/laravel-activity-log
```

Publishing Configuration and Migrations
---------------------------------------

[](#publishing-configuration-and-migrations)

```
php artisan vendor:publish --provider="Shkiper\ActivityLog\ActivityLogServiceProvider"
```

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

[](#configuration)

Configuration is located in the `config/activity-log.php` file. You can specify:

- Driver for storing logs (`mysql`, `mongodb`, `clickhouse`)
- Database connection
- Queue settings for asynchronous logging
- Other parameters

Main Features
-------------

[](#main-features)

### 1. Logging Changes in Models with Template Support

[](#1-logging-changes-in-models-with-template-support)

Add the `LogsActivity` trait to your model:

```
use Shkiper\ActivityLog\Traits\LogsActivity;

class User extends Model
{
    use LogsActivity;

    // Which fields to log
    protected static $logAttributes = ['name', 'email'];

    // Log name
    protected static $logName = 'users';

    // Log only changed attributes (recommended)
    protected static $logOnlyDirty = true;

    // Which events to log
    protected static $logEvents = ['created', 'updated', 'deleted'];
}
```

### 2. Manual Logging of Actions

[](#2-manual-logging-of-actions)

```
use Shkiper\ActivityLog\Facades\ActivityLog;

// Example of logging a user action with a template
ActivityLog::inLog('user_actions')
    ->causedBy($user)
    ->performedOn($article)
    ->withEvent('published')
    ->withTemplate('{causer.name} published article "{subject.title}"')
    ->withProperties([
        'action' => 'published',
        'ip' => request()->ip(),
        'user_agent' => request()->userAgent(),
    ])
    ->withContext([
        'platform' => 'web',
        'browser' => 'Chrome'
    ])
    ->log();

// Example of logging a system action
ActivityLog::inLog('system')
    ->withDescription('Mailing started')
    ->withProperties([
        'email_count' => 150,
        'campaign_id' => 123,
    ])
    ->log();
```

### 3. Grouping Logs in a Batch

[](#3-grouping-logs-in-a-batch)

```
// Start logging with one UUID for related actions
$batchUuid = \Shkiper\ActivityLog\Traits\LogsActivity::startBatch();

// Creation/updating of models

// Or you can manually add to the group
ActivityLog::withBatch($batchUuid)
    ->inLog('batch_actions')
    ->withDescription('Action in group')
    ->log();

// End batch logging
\Shkiper\ActivityLog\Traits\LogsActivity::endBatch();
```

### 4. Retrieving Logs

[](#4-retrieving-logs)

```
// Through the repository
app(\Shkiper\ActivityLog\Contracts\ActivityLogRepository::class)
    ->findByLogName('users');

// Through Eloquent (if using MySQL)
\Shkiper\ActivityLog\Models\Activity::inLog('users')
    ->causedBy($user)
    ->latest()
    ->get();
```

Usage
-----

[](#usage)

Add logging to a model:

```
use Shkiper\ActivityLog\Traits\LogsActivity;

class User extends Model
{
    use LogsActivity;

    protected static $logAttributes = ['name', 'email'];
}
```

Log an action manually:

```
ActivityLog::inLog('user_actions')
    ->causedByCurrentUser()
    ->withTemplate("User {causer.name} performed an action")
    ->withContext(['additional' => 'data'])
    ->log();
```

Usage Examples
--------------

[](#usage-examples)

### Logging User Changes

[](#logging-user-changes)

```
// User.php
use Shkiper\ActivityLog\Traits\LogsActivity;

class User extends Authenticatable
{
    use LogsActivity;

    protected static $logAttributes = ['name', 'email', 'status'];
    protected static $logName = 'users';
}

// When $user->update(['status' => 'active']) is called,
// a log entry will be created with the old and new values saved
```

### Custom Messages in Logs

[](#custom-messages-in-logs)

```
// Comment.php
use Shkiper\ActivityLog\Traits\LogsActivity;

class Comment extends Model
{
    use LogsActivity;

    protected static $logAttributes = ['content'];
    protected static $logName = 'comments';

    // Custom event description
    public function getActivityDescription(string $eventName): string
    {
        return match($eventName) {
            'created' => "User added a comment to article {$this->article->title}",
            'updated' => "User edited a comment on article {$this->article->title}",
            'deleted' => "User deleted a comment from article {$this->article->title}",
            default => $eventName,
        };
    }
}
```

### Manual Action Logging

[](#manual-action-logging)

```
class MessageController
{
    public function send(Request $request, User $recipient)
    {
        // Message sending logic
        $message = Message::create([...]);

        // Logging the action
        ActivityLog::inLog('messaging')
            ->causedByCurrentUser()
            ->performedOn($message)
            ->withDescription("Message sent to user {$recipient->name}")
            ->withProperties([
                'message_type' => $request->type,
                'recipient_id' => $recipient->id,
                'content_length' => strlen($request->content),
            ])
            ->log();

        return response()->json(['success' => true]);
    }
}
```

Working with Different Storages
-------------------------------

[](#working-with-different-storages)

### MySQL (default)

[](#mysql-default)

```
// .env
ACTIVITY_LOG_DRIVER=mysql
```

### MongoDB

[](#mongodb)

```
// .env
ACTIVITY_LOG_DRIVER=mongodb
ACTIVITY_LOG_MONGODB_CONNECTION=mongodb
ACTIVITY_LOG_MONGODB_COLLECTION=activity_logs
```

### ClickHouse

[](#clickhouse)

```
// .env
ACTIVITY_LOG_DRIVER=clickhouse
ACTIVITY_LOG_CLICKHOUSE_CONNECTION=clickhouse
ACTIVITY_LOG_CLICKHOUSE_TABLE=activity_logs
```

Message Templating
------------------

[](#message-templating)

The package supports customizing log display through a template system.

### Standard Templates

[](#standard-templates)

Standard templates for events can be configured in the configuration file:

```
// config/activity-log.php
'templates' => [
    'created' => '{causer.name} created {subject.type} "{subject.name}"',
    'updated' => '{causer.name} updated {subject.type} "{subject.name}"',
    'deleted' => '{causer.name} deleted {subject.type} "{subject.name}"',
    // add your templates for different events
],
```

### Available Variables in Templates

[](#available-variables-in-templates)

- `{causer}` - the model that performed the action
- `{causer.name}` - access to causer properties
- `{subject}` - the model on which the action was performed
- `{subject.title}` - access to subject properties
- `{properties.key}` - access to values from the properties array
- `{context.key}` - access to values from the context array
- `{changes.old.field}` - old value of a changed field
- `{changes.new.field}` - new value of a changed field

### Registering Custom Templates

[](#registering-custom-templates)

```
// In a service provider
use Shkiper\ActivityLog\Templates\TemplateProcessor;

public function boot()
{
    TemplateProcessor::registerTemplates([
        'login' => 'User {causer.name} logged into the system from IP {context.ip}',
        'payment' => 'Payment of {properties.amount} for {subject.type} #{subject.id}'
    ]);
}
```

### Getting Formatted Descriptions

[](#getting-formatted-descriptions)

```
// Through the presenter
$activity = Activity::first();
$formattedDescription = $activity->presenter()->description();

// Or through the accessor
$formattedDescription = $activity->formatted_description;

// Applying another template for display
$customDescription = $activity->presenter()->renderTemplate(
    'User {causer.name} changed field {changes.new.title}'
);
```

License
-------

[](#license)

MIT

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance52

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

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 ~51 days

Total

4

Last Release

406d ago

Major Versions

v0.0.2 → 1.0.02025-03-31

PHP version history (2 changes)v0.0.1PHP ^8.0

1.0.0PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

laravelloggingAudit

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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)
