PHPackages                             uatthaphon/laravel-activity-monitor - 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. uatthaphon/laravel-activity-monitor

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

uatthaphon/laravel-activity-monitor
===================================

The activity logged to monitor your website

0.1.8(8y ago)012MITPHPPHP ^7.0

Since Feb 16Pushed 6y agoCompare

[ Source](https://github.com/uatthaphon/laravel-activity-monitor)[ Packagist](https://packagist.org/packages/uatthaphon/laravel-activity-monitor)[ RSS](/packages/uatthaphon-laravel-activity-monitor/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (5)Versions (9)Used By (0)

laravel-activity-mornitor
=========================

[](#laravel-activity-mornitor)

Activity Monitor Log is an activity logger for monitoring user activity and eloquent models events activity.

**Note:** This package use laravel 5.5+ it require php 7.0+

Setup
-----

[](#setup)

Add package dependency to your project

```
composer require uatthaphon/laravel-activity-monitor
```

As the package build for laravel 5.5+, I use [Auto-Discovery](https://laravel-news.com/package-auto-discovery)so we don't need to add service provider in `config\app.php` anymore

Run publishing to get the database migration for table `activity_monitors`

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

After published, we can create table by running the migrations

```
php artisan migrate
```

Usage
-----

[](#usage)

### Logger

[](#logger)

This package have 2 aliases `AMLog` and `AMView` for us to easily use to save the log and view the logs.

We don't need to add those 2 aliases to `config/app.php` neither. It already added for us by [Auto-Discovery](https://laravel-news.com/package-auto-discovery).

Example, log the user updated their post.

```
use AMLog;

$post = Post::where('user_id', $id)->firstOrFail();
$post->body = 'update body content';
$post->save();

AMLog::logName('custom log name')               // Declare log name
    ->description('user updated post content')  // Log description
    ->happenTo($post)                           // Model of the event happen to
    ->actBy(\Auth::user())                      // Model that cause this event
    ->meta(['key'=>'value'])                    // Additional pieces of information
    ->save();                                   // Let's Save the log
```

AMlog also prepared some of the log name for us to easily use =&gt; `debug`, `error`, `fatal`, `info`, `warning`

```
use AMLog;
...
AMLog::debug('some debug description')->save();

AMLog::error('some error description')->save();

AMLog::fatal('some fatal description')->save();

AMLog::info('some info description')->save();

AMLog::warning('some warning description')->save();
```

That's it 🎶

### Eloquent Models Events Log

[](#eloquent-models-events-log)

For you to easy log your eloquent model activities when `created`, `updated`, `deleted`.

After you setting up the package then add `ModelEventActivity` Trait to your model.

```
namespace App\Models;

...
use Uatthaphon\ActivityMonitor\Traits\ModelEventActivity;

class ToBelog extends Model
{
    use ModelEventActivity;
    ...
}
```

This feature will record only changes in your application by setting `protected static $loggable` to tell the logger which attributes should be logs.

**Note: It will not log attribute that use database default value... Except you add value to the attribute by your self**

```
...
use Uatthaphon\ActivityMonitor\Traits\ModelEventActivity;

class ToBelog extends Model
{
    use ModelEventActivity;

    protected static $loggable = ['title', 'description']
}
```

If `title` record changed, It will only log title field in the table `activity_monitors`

```
{"title": "has some change"}
```

We can cutomize which eloquent event should be log by `protected static $eventsToLog`.

In the example below only `created` event for this model will be logged

```
...
use Uatthaphon\ActivityMonitor\Traits\ModelEventActivity;

class ToBelog extends Model
{
    use ModelEventActivity;

    protected static $eventsToLog = ['created']
}
```

We can add our meta data to each event by add this to yout model

```
...
use Uatthaphon\ActivityMonitor\Traits\ModelEventActivity;

class ToBelog extends Model
{
    use ModelEventActivity;

    protected static $createdEventMeta = ['create key' => 'create value'];

    protected static $updatedEventMeta = ['update key' => 'update value'];

    protected static $deletedEventMeta = ['deletd key' => 'delete value'];

    ...
}
```

View Logs
---------

[](#view-logs)

We can use `AMView` to get our logs it will return as ActivityMonitor

See this example below

```
use AMView;

...

// Get all
AMView::all();                                    // get all the logs
AMView::get();                                    // also act the same as all()

// With conditions
AMView::logName('your_log_name')                  // get by log name
    ->limit(5)                                    // limit resutls
    ->sortBy('desc')                              // sort By desc or asc
    ->get();

// Get from multiple log names
AMView::logName('info', 'updated')->get();
AMView::logName(['info', 'updated'])->get();

// Get all specific lastest post log From current user
$user = \Auth::user();
$post = $user->post()->last($user);
AMView::happenTo($post)->ActBy($user)->get();

// Or call from providings log name function
AMView::debug()->all();

AMView::error()->all();

AMView::fatal()->all();

AMView::info()->all();

AMView::warning()->all();

...
```

Try and see. It will return collection of `ActivityMonitor` model

```
use AMView;

...

$am = AMView::info()->all()->last();

$am->log_name;                          // Get log name
$am->description;                       // Get description
$am->agent;                             // Get user browser agent
$am->ip;                                // Get user ip address

$traces = $am->traces;                  // Get traces

foreach ($traces as $key => $value) {
    // do something
}

$meta = $am->meta;                      // Get you custom meta data

foreach ($meta as $key => $value) {
    // do something
}

...
```

View Log In Specific Model
--------------------------

[](#view-log-in-specific-model)

We can add `ActivityMonitor` to our model

```
...
use Uatthaphon\ActivityMonitor\Traits\ActivityMonitorRelations;

class User extends Authenticatable
{
  use ActivityMonitorRelations;

  ...
}
```

Now we can use `activity()` polymorphic relations

```
// Get all activity records of the current user
\Auth::user()->activity()->get();

// Retrived with more specific
// By tell with model record user was interact with
$user = \Auth::user();
$user->activity()->happenTo($user->posts()-last())->get();

// Use the providing log name function
$user->activity()->info()->get();

// Use the providing log name with specific fom model togetter
$user->activity()
    ->info()
    ->happenTo($user->posts()-last())
    ->get();
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

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

Total

7

Last Release

3005d ago

PHP version history (2 changes)0.1.0PHP ^7.0

0.1.4PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/37b259dc83a031f066f594771210fd8e5bbbf63c01dfc27372d992d7fd4825a4?d=identicon)[uatthaphon](/maintainers/uatthaphon)

---

Top Contributors

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

---

Tags

loglaravelmonitoracitivty

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/uatthaphon-laravel-activity-monitor/health.svg)

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

###  Alternatives

[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[jackiedo/log-reader

An easy log reader and management tool for Laravel

151376.5k4](/packages/jackiedo-log-reader)[masterro/laravel-mail-viewer

Easily view in browser outgoing emails.

6392.1k](/packages/masterro-laravel-mail-viewer)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[aedart/athenaeum

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

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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