PHPackages                             yungts97/laravel-user-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. [Database &amp; ORM](/categories/database)
4. /
5. yungts97/laravel-user-activity-log

ActiveLibrary[Database &amp; ORM](/categories/database)

yungts97/laravel-user-activity-log
==================================

A simple laravel package by yungts97 to easily monitor your laravel app user activity.

v1.4.2(1y ago)2323.0k—6.8%2[2 issues](https://github.com/yungts97/laravel-user-activity-log/issues)MITPHP

Since Jan 22Pushed 1y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (2)Versions (11)Used By (0)

[![Logo mark of Laravel User Activity Log](/art/background.png)](/art/background.png)

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

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

 [ ![](https://camo.githubusercontent.com/2178e9d272dc46133dadc61306bafcbf5421c139d73ef69d971f589d828ba173/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f79756e67747339372f6c61726176656c2d757365722d61637469766974792d6c6f673f636f6c6f723d323442444343) ](https://packagist.org/packages/yungts97/laravel-user-activity-log) [ ![](https://camo.githubusercontent.com/317df4abd0761c4eae52fca66d30e47304a52cfeca44a69f7448c55aad30648b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f79756e67747339372f6c61726176656c2d757365722d61637469766974792d6c6f67) ](https://github.com/yungts97/laravel-user-activity-log/blob/v1.0.0/LICENSE.md) [ ![](https://camo.githubusercontent.com/13ce48c892706a449f182e24a5a3c920248d1d5fe811734d83e6f1316c82fb0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f79756e67747339372f6c61726176656c2d757365722d61637469766974792d6c6f673f636f6c6f723d666636396234) ](https://packagist.org/packages/yungts97/laravel-user-activity-log) [ ![](https://github.com/yungts97/laravel-user-activity-log/workflows/CI/badge.svg) ](https://github.com/yungts97/laravel-user-activity-log/actions)

`yungts97/laravel-user-activity-log` is a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app. It provides automatic logging for the model events without complicated action. All activity will be stored in the `logs` table.

📦 Environment Requirements
--------------------------

[](#-environment-requirements)

`PHP`: ^8.0

`Laravel`: ^8.x - ^9.0

🚀 Installation
--------------

[](#-installation)

You can install the package via composer:

```
composer require yungts97/laravel-user-activity-log
```

The package will automatically register a service provider.

After that, we still need one more step to complete the installation by run this command.

```
php artisan user-activity-log:install
```

✨ How to use?
-------------

[](#-how-to-use)

This package is very simple and easy to use. The only thing you need to do is add the `Loggable` trait in your model class.

```
use Illuminate\Database\Eloquent\Model;
use Yungts97\LaravelUserActivityLog\Traits\Loggable;

class Post extends Model
{
    use Loggable; // add it in here
    ...
}
```

It might troublesome if you have a lot of models. You could have a base class for your models and add `Loggable` trait in your base model.

```
# BaseModel.php
use Illuminate\Database\Eloquent\Model;
use Yungts97\LaravelUserActivityLog\Traits\Loggable;

class BaseModel extends Model
{
    use Loggable;
}

# PostModel.php
class Post extends BaseModel
{
    ...
}
```

If you don't want to log for any child class of the base model, you can add `SkipLogging` trait to skip the log for the model.

```
use Yungts97\LaravelUserActivityLog\Traits\SkipLogging;

class Post extends BaseModel
{
    use SkipLogging;
    ...
}
```

Sometimes, you don't want to save certain attributes of your model in logging. You can add `$log_hidden` attribute to your model.

```
use Yungts97\LaravelUserActivityLog\Traits\SkipLogging;

class Post extends BaseModel
{
    public $log_hidden = ['created_at', 'description'];
    ...
}
```

You can retrieve all activity using the `Yungts97\LaravelUserActivityLog\Models\Log` model.

```
Log::all();
```

However, you can get activity logs from a model by using this.

```
$post->logs; // get all model's logs
$post->log; // get the latest model's log
$post->logs()->where('log_type', 'edit')->get(); // get filtered logs
```

You allowed to specify the mode for the `edit` event log. There are two modes available now `simple`/`full`. The default mode is `full`.

```
# config/user-activity-log.php

# only can choose either one of them
'mode' => 'full',   # the 'full' mode record everything
'mode' => 'simple', # the 'simple' mode only record the modified columns
```

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

[](#️-configuration)

You can change the configuration of this package on `config/user-activity-log.php`.

```
return [
    # add your own middleware here (route middleware)
    'middleware' => ['api', 'auth'],

    # user model class
    'user_model' =>  "App\Models\User",

    # exclude tables for filter option
    'exclude_tables' => [
        'logs',
        'migrations',
        'failed_jobs',
        'password_resets',
        'personal_access_tokens',
    ],

    # events to log
    'events' => [
        'create' => true,
        'edit'   => true,
        'delete' => true,
        'retrieve' => false,
        'login'  => true,
        'logout' => true
    ],

    # the mode is only for 'edit' event log
    # the 'simple' mode only record the modified columns
    # the 'full' mode record everything
    # supported mode => 'simple' / 'full'
    'mode' => 'full',

    # timezone for log date time (Change to your region time zone, or any other variation of the timezone key in .env)
    # UTC is the default the time zone being recorded.
    # define your timezone to have the accurate logs time and filtered record (Especially filtered by date time)
    'timezone' => env('APP_TIMEZONE','UTC')
];
```

🐣 API Routes
------------

[](#-api-routes)

EndpointMethodResponse FormatDescription`/logs``GET`JSONTo retrieve user activity logs.`/logs/filter-options``GET`JSONTo retrieve filter options for filtering logs.`/logs/{log_id}``GET   `JSONTo retrieve specific activity log.Available paramaters for log filtering:

ParameterTypeDescription`page``integer`The page number for log pagination.`itemsPerPage``integer`The number item per page for log pagination`userId``integer`Filtering logs by the user ID.`dataId``integer`Filtering logs by the data ID.`logType``string`Filtering logs by log type.`tableName``string`Filtering logs by the table name.`dateFrom``string`Filtering logs by the date range. **(Must have dateFrom &amp; dateTo paramaters)**`dateTo``string`Filtering logs by the date range. **(Must have dateFrom &amp; dateTo paramaters)**Exp. `http://example.com/api/logs?page=1&itemsPerPage=10&userId=517`

### 📬 Sample Response

[](#-sample-response)

`/logs`

```
{
    "current_page": 1,
    "data": [
        {
            "id": 77,
            "user_id": 942,
            "log_datetime": "2022-01-22T05:56:57.000000Z",
            "table_name": null,
            "log_type": "login",
            "request_info": {
                "ip": "192.121.0.56",
                "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
            },
            "data": null,
            "current_data": null,
            "humanize_datetime": "17 seconds ago",
            "user": {
                "id": 1,
                "name": "User 1",
            }
        },
    ],
    "first_page_url": "http://localhost/api/logs?page=1",
    "from": 1,
    "last_page": 1,
    "last_page_url": "http://localhost/api/logs?page=1",
    "links": [
        {
            "url": null,
            "label": "&laquo; Previous",
            "active": false
        },
        {
            "url": "http://localhost/api/logs?page=1",
            "label": "1",
            "active": true
        },
    ],
    "next_page_url": null,
    "path": "http://localhost/api/logs",
    "per_page": "10",
    "prev_page_url": null,
    "to": 10,
    "total": 1
}
```

`/logs/filter-options`

```
{
    "table_names": [
        "posts",
        "users",
    ],
    "log_types": [
        "create",
        "edit",
        "delete",
        "login",
        "logout"
    ]
}
```

`/logs/77`

```
{
    "id": 77,
    "user_id": 942,
    "log_datetime": "2022-01-22T05:56:57.000000Z",
    "table_name": null,
    "log_type": "login",
    "request_info": {
        "ip": "192.121.0.56",
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
    },
    "data": null,
    "current_data": null,
    "humanize_datetime": "17 seconds ago",
    "user": {
        "id": 1,
        "name": "User 1",
    }
},
```

🎩 Artisan Commands
------------------

[](#-artisan-commands)

CommandDescriptionOptionuser-activity-log:installPreparing all the files it needed for the user activity log package.N/Auser-activity-log:flushRemove all the user activity log records that in the database.N/Auser-activity-log:cleanRemove the user activity log records that in the database.`--day`, `--month`, `--year`, `--date`### ✒️ Options for `user-activity-log:clean`

[](#️-options-for-user-activity-logclean)

OptionValueExampleDescription`--day`numeric`--day=7`Delete user activity log older than N days.`--month`mm/yyyy`--month=01/2022`Delete user activity logs for a month of the year.`--year`yyyy`--year=2022`Delete user activity logs for a year.`--date`yyyy`--date=15/02/2022`Delete user activity logs for a specific date.`⚠️ Notice:` Without any option applied by default is `--day=7`

📃 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.2% 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 ~105 days

Recently: every ~214 days

Total

10

Last Release

629d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/88c0b9b1b06c681d4a646bdd38ae62d3cc3ac8294a910d49e5b202b7b390d45b?d=identicon)[yungts97](/maintainers/yungts97)

---

Top Contributors

[![yungts97](https://avatars.githubusercontent.com/u/48639619?v=4)](https://github.com/yungts97 "yungts97 (71 commits)")[![yungtssains](https://avatars.githubusercontent.com/u/217894983?v=4)](https://github.com/yungtssains "yungtssains (5 commits)")[![joako407](https://avatars.githubusercontent.com/u/18098027?v=4)](https://github.com/joako407 "joako407 (1 commits)")

---

Tags

audit-traileloquentlaravellaravel-packageloggerloggingloglaraveluseractivity

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

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

PHPackages © 2026

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