PHPackages                             testmonitor/laravel-accountable - 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. testmonitor/laravel-accountable

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

testmonitor/laravel-accountable
===============================

Tracks the user responsible for creating, modifying, or deleting an Eloquent model

10.1.0(8mo ago)811.3k↓50%3[1 PRs](https://github.com/testmonitor/laravel-accountable/pulls)MITPHPPHP ^8.2

Since Apr 24Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/testmonitor/laravel-accountable)[ Packagist](https://packagist.org/packages/testmonitor/laravel-accountable)[ RSS](/packages/testmonitor-laravel-accountable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (24)Used By (0)

Accountable Eloquent models
===========================

[](#accountable-eloquent-models)

[![Latest Stable Version](https://camo.githubusercontent.com/7ee4ef55b7bede068b96c4a374c04a36f21f52521ad2bb4760d794a1b763cad6/68747470733a2f2f706f7365722e707567782e6f72672f746573746d6f6e69746f722f6c61726176656c2d6163636f756e7461626c652f762f737461626c65)](https://packagist.org/packages/testmonitor/laravel-accountable)[![CircleCI](https://camo.githubusercontent.com/0701ba77651292c6841cbf9ddf3a5356fd7455e9388e0c40da11eee28bb5f5ee/68747470733a2f2f696d672e736869656c64732e696f2f636972636c6563692f70726f6a6563742f6769746875622f746573746d6f6e69746f722f6c61726176656c2d6163636f756e7461626c652e737667)](https://circleci.com/gh/testmonitor/laravel-accountable)[![StyleCI](https://camo.githubusercontent.com/b44deebe243f8b47a211468f0afc6707324d4ceecdf770bae3b62c7f9052ca76/68747470733a2f2f7374796c6563692e696f2f7265706f732f38393039363338382f736869656c64)](https://styleci.io/repos/89096388)[![codecov](https://camo.githubusercontent.com/bac5677a5c0e06b0d1fb61d5515bf223264fbe783690434ae456005fa7bf6acc/68747470733a2f2f636f6465636f762e696f2f67682f746573746d6f6e69746f722f6c61726176656c2d6163636f756e7461626c652f67726170682f62616467652e7376673f746f6b656e3d59315a4e554550463855)](https://codecov.io/gh/testmonitor/laravel-accountable)[![License](https://camo.githubusercontent.com/d4db029f028343a7624af5c9f9d363aa95422296cd6ec27d3fc6aca639e46225/68747470733a2f2f706f7365722e707567782e6f72672f746573746d6f6e69746f722f6c61726176656c2d6163636f756e7461626c652f6c6963656e7365)](https://packagist.org/packages/laravel-accountable)

This package provides a trait that tracks the user responsible for creating, modifying, or deleting an Eloquent model.

Accountable will observe any activity on your models and it sets the **created\_by\_user\_id**, **updated\_by\_user\_id**, and **deleted\_by\_user\_id**accordingly using the currently authenticated user.

It also provides you with some useful scope query functions, allowing you to fetch models that were either created, modified, or deleted by a specific user.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Using the Migration helper](#using-the-migration-helper)
    - [Using the Trait](#using-the-trait)
- [Examples](#examples)
- [Tests](#tests)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

This package can be installed through Composer:

```
$ composer require testmonitor/laravel-accountable
```

The package will automatically register itself.

Optionally, publish the configuration file:

```
$ php artisan vendor:publish --provider="TestMonitor\Accountable\AccountableServiceProvider" --tag="config"
```

The configuration file allows you to set the preferred authentication driver, the database column names, and anonymous user. The latter can be used to deal with records created/updated by unauthenticated users.

When left untouched, Accountable will use the default authentication driver and the default column names (*created\_by\_user\_id*, *updated\_by\_user\_id*, and *deleted\_by\_user\_id*).

Usage
-----

[](#usage)

In order to add Accountable to your Laravel application, you'll need to:

1. Add the required columns to your migration file(s).
2. Use the trait `TestMonitor\Accountable\Traits\Accountable` on your model(s).

*Please note that due to the nature of Laravel event system, mass updates will not be handled by Accountable.*

### Using the Migration helper

[](#using-the-migration-helper)

The migration helper simplifies the process of adding columns to your migration:

```
use TestMonitor\Accountable\Accountable;

class CreateProjectsTable extends Migration
{
    public function up()
    {
        Schema::create('projects', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');

            $table->timestamps();
            $table->softDeletes();

            // This will add the required columns
            Accountable::columns($table);
        });
    }
}
```

Tip: if you do not use soft-deletes on your model, use `Accountable::columns($table, false)` to prevent the helper from adding a *deleted\_by\_user\_id* column.

### Using the Trait

[](#using-the-trait)

Add the Accountable trait on the models you want to track:

```
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use TestMonitor\Accountable\Traits\Accountable;

class Project extends Model
{
    use Accountable, SoftDeletes;

    protected $table = 'projects';
}
```

Examples
--------

[](#examples)

Set up your model and make sure you are authenticated.

### Basics

[](#basics)

Create a project and show the name of the user that created it:

```
$project = new Project(['name' => 'Awesome project']);
$project->save();

// Show the name of user that created the project
echo $project->creator->name;
```

Get all projects created by a specific user:

```
$user = User::findOrFail(42);

// Get all projects created by user with id 42
Project::onlyCreatedBy($user)->get();
```

### Properties

[](#properties)

You can use the following properties and methods to reveal the user responsible for creating, updating or deleting the record.

```
// Get the user that created the model
$model->created_by_user_id;
$model->creator->name;

// Get the user that last updated the model
$model->updated_by_user_id;
$model->editor->name;

// Get the user that last deleted the model
$model->deleted_by_user_id;
$model->deleter->name;
```

### Scope Queries

[](#scope-queries)

The following scope queries are at your disposal:

```
// Retrieve the models either created, updated,
// or deleted by $user.
Model::onlyCreatedBy($user)->get();
Model::onlyUpdatedBy($user)->get();
Model::onlyDeletedBy($user)->get();

// And one extra: get all models that were created
// by the currently authenticated user.
Model::mine()->get();
```

### Disable Logging

[](#disable-logging)

In some cases, you don't want to automatically save the user along with the model (for example: when seeding test data). You can disable accountable by using the `disableUserLogging` method.

```
$project = new Project(['name' => 'Do not track me']);
$project->disableUserLogging()->save();
```

If you want to re-enable accountable, simply use the `enableUserLogging`method afterwards.

### Impersonation

[](#impersonation)

When authentication is not available - for example, when running jobs in a queue - you might want to "impersonate" a user. Simply override user identification with the `actingAs` method:

```
accountable()->actingAs($event->causer);
```

You can end the impersonation by calling the `reset` method.

Tests
-----

[](#tests)

The package contains integration tests. You can run them using PHPUnit.

```
$ vendor/bin/phpunit

```

Changelog
---------

[](#changelog)

Refer to [CHANGELOG](CHANGELOG.md) for more information.

Contributing
------------

[](#contributing)

Refer to [CONTRIBUTING](CONTRIBUTING.md) for contributing details.

Credits
-------

[](#credits)

- **Thijs Kok** - *Lead developer* - [ThijsKok](https://github.com/thijskok)
- **Stephan Grootveld** - *Developer* - [Stefanius](https://github.com/stefanius)
- **Frank Keulen** - *Developer* - [FrankIsGek](https://github.com/frankisgek)
- **Muriel Nooder** - *Developer* - [ThaNoodle](https://github.com/thanoodle)

- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Refer to the [License](LICENSE.md) for more information.

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance64

Regular maintenance activity

Popularity30

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 83.8% 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 ~153 days

Recently: every ~223 days

Total

21

Last Release

245d ago

Major Versions

5.1.0 → 6.0.02022-04-04

6.0.0 → 7.0.02023-04-09

7.0.0 → 8.0.02023-06-28

8.0.0 → 9.0.02024-11-27

9.0.0 → 10.0.02025-04-09

PHP version history (6 changes)1.0.0PHP ^7.0

3.1.0PHP ^7.2

5.0.0PHP ^7.4|^8.0

6.0.0PHP ^8.0

7.0.0PHP ^8.1

9.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/47f66133b6b4806a16aaed043daa733f5e97adb7a10c9982d01a1cda9f492040?d=identicon)[stefanius](/maintainers/stefanius)

![](https://www.gravatar.com/avatar/39f48c881813b7d3b044ca5660aa5ab9e60b5dd7c34ed4a47acbb11bd20b7593?d=identicon)[thijskok](/maintainers/thijskok)

---

Top Contributors

[![thijskok](https://avatars.githubusercontent.com/u/1344550?v=4)](https://github.com/thijskok "thijskok (109 commits)")[![stefanius](https://avatars.githubusercontent.com/u/2707905?v=4)](https://github.com/stefanius "stefanius (20 commits)")[![Frankisgek](https://avatars.githubusercontent.com/u/487218?v=4)](https://github.com/Frankisgek "Frankisgek (1 commits)")

---

Tags

createddeletedeloquentlaravelupdateduserlaraveleloquentusercreateddeletedtestmonitormodified

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/testmonitor-laravel-accountable/health.svg)

```
[![Health](https://phpackages.com/badges/testmonitor-laravel-accountable/health.svg)](https://phpackages.com/packages/testmonitor-laravel-accountable)
```

###  Alternatives

[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M253](/packages/cviebrock-eloquent-sluggable)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)

PHPackages © 2026

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