PHPackages                             jvizcaya/loggable - 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. jvizcaya/loggable

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

jvizcaya/loggable
=================

Provides functions to record user activities in the application models.

v0.9.8(4y ago)0106MITPHPPHP ^7.1.3|^8.0

Since Feb 11Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jvizcaya/loggable)[ Packagist](https://packagist.org/packages/jvizcaya/loggable)[ RSS](/packages/jvizcaya-loggable/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)DependenciesVersions (21)Used By (0)

Loggable (Provides functions to record user activities in the application models.)
==================================================================================

[](#loggable-provides-functions-to-record-user-activities-in-the-application-models)

**Loggable** is a package for Laravel 5.7+ that adds functionalities to record user activities on the tables in the application database, inspired by the [haruncpi/laravel-user-activity](https://github.com/haruncpi/laravel-user-activity) package.

Loggable saves a record in the **logs** table each time a user performs an operation on each model that uses the **Trait** on the **created**, **updated** and **deleted** events.

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

[](#installation)

```
composer require jvizcaya/loggable

```

We publish the config file if we want to change the table name in the database used by this package, as well as other options.

```
php artisan vendor:publish --provider="Jvizcaya\Loggable\LoggableServiceProvider"

```

Run the migration to export the **logs** table in the database.

```
php artisan migrate

```

Use mode
--------

[](#use-mode)

Add the trait `Jvizcaya\Loggable\Loggable` to the model of the table we want the user activity logs to be saved.

```
namespace App;

use Illuminate\Database\Eloquent\Model;
use Jvizcaya\Loggable\Loggable;

class Post extends Model
{
    use Loggable;

}
```

That's all, in the previous example a record will be made in the **logs** table every time a user saves, updates or deletes in the **Post** model table.

Retrieve models logs
--------------------

[](#retrieve-models-logs)

This package was built in using the Laravel [one-to-many polymorphic relationship](https://laravel.com/docs/8.x/eloquent-relationships#one-to-many-polymorphic-relations) convention and the trait `Jvizcaya\Loggable\Loggable` has the model relationship definition.

**Load post logs**

```
use App\Models\Post;

$logs = Post::find(1)->logs;
```

**Lazy Eager Loading**

```
use App\Models\Post;

$posts = Post::with('logs')->get();
```

**Scope lastLogs($limit = 10, $loadUser = true, $userColumns = 'id,name')**

Optionally we can use the scope **lastLogs** to load the model last logs. This function accepts as the first parameter the maximum number of results.

```
Post::lastLogs(10)->get();
```

By default this function loads the user data associated with each log. If we want to select the columns of the user table, we can pass a string with the names of the columns separated by a comma(,) as the third parameter.

```
Post::lastLogs(10, true, 'id,name,email,status')->get();
```

To disable the loading of user data, pass a boolean false as the second parameter.

```
Post::lastLogs(20, false)->get();
```

Log model data
--------------

[](#log-model-data)

By default, model data will be saved to the payload object's data attribute on **delete** operations. You can disable this functionality by setting the **log\_data** variable in the configuration file to **false**.

Logs delete (console command)
-----------------------------

[](#logs-delete-console-command)

To delete the activity log data, we can use the available console command **loggable:delete**, this command will delete the logs that are older than the days defined in the loggable.php configuration file (30 days by default).

```
php artisan loggable:delete

```

Optionally, we can pass the value of the days as the command argument.

```
php artisan loggable:delete 5

```

Add the console command **loggable:delete** to [Task scheduling](https://laravel.com/docs/8.x/scheduling) for run the command automatically.

---

Note
----

[](#note)

This package use the model file `Jvizcaya\Loggable\Models\Log`.

License
-------

[](#license)

[MIT](LICENSE) © Jorge Vizcaya |

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Recently: every ~1 days

Total

20

Last Release

1517d ago

PHP version history (2 changes)v0.1PHP ^7.1.3

v0.7.2PHP ^7.1.3|^8.0

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

loglaravelmodeluser

### Embed Badge

![Health badge](/badges/jvizcaya-loggable/health.svg)

```
[![Health](https://phpackages.com/badges/jvizcaya-loggable/health.svg)](https://phpackages.com/packages/jvizcaya-loggable)
```

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