PHPackages                             phumsoft/userstamps - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. phumsoft/userstamps

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

phumsoft/userstamps
===================

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

02PHP

Since Jan 25Pushed 4y agoCompare

[ Source](https://github.com/phumsoft/userstamps)[ Packagist](https://packagist.org/packages/phumsoft/userstamps)[ RSS](/packages/phumsoft-userstamps/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

 [![](https://camo.githubusercontent.com/64a781e698b8668d7c5b477e6ddb775a4e35bad3c63100c54f83abf827f43aa0/68747470733a2f2f73332d65752d776573742d312e616d617a6f6e6177732e636f6d2f77732e686f737465642f757365727374616d70732d6c6f676f2e737667)](https://camo.githubusercontent.com/64a781e698b8668d7c5b477e6ddb775a4e35bad3c63100c54f83abf827f43aa0/68747470733a2f2f73332d65752d776573742d312e616d617a6f6e6177732e636f6d2f77732e686f737465642f757365727374616d70732d6c6f676f2e737667)

 [ ![Build Status](https://camo.githubusercontent.com/2d7b00838abfb9a09f4dff0b51302091a50acc01af62757b30ff330861924fbe/68747470733a2f2f7472617669732d63692e636f6d2f5068756d736f6674554b2f4c61726176656c2d557365727374616d70732e737667) ](https://github.com/flutter/flutter/actions/workflows//badge.svg) [ ![Total Downloads](https://camo.githubusercontent.com/3a6a478a665f19febc60c679b183fef6e9b0dcdba1bf125eb33a360024362a04/68747470733a2f2f706f7365722e707567782e6f72672f7068756d736f66742f757365727374616d70732f642f746f74616c2e737667) ](https://packagist.org/packages/phumsoft/userstamps) [ ![Latest Stable Version](https://camo.githubusercontent.com/a5a0928f87f6b218a22564ce29029db2495fa6a63ac0137facdcc5b3ad736d28/68747470733a2f2f706f7365722e707567782e6f72672f7068756d736f66742f757365727374616d70732f762f737461626c652e737667) ](https://packagist.org/packages/phumsoft/userstamps) [ ![License](https://camo.githubusercontent.com/5e943ec9d07113de24257b4827f33df47a752dd8c1b55c3c063f0db4d62acc97/68747470733a2f2f706f7365722e707567782e6f72672f7068756d736f66742f757365727374616d70732f6c6963656e73652e737667) ](https://packagist.org/packages/phumsoft/userstamps)

About Laravel Userstamps
------------------------

[](#about-laravel-userstamps)

Laravel Userstamps provides an Eloquent trait which automatically maintains `created_by` and `updated_by` columns on your model, populated by the currently authenticated user in your application.

When using the Laravel `SoftDeletes` trait, a `deleted_by` column is also handled by this package.

Installing
----------

[](#installing)

This package requires Laravel 5.2 or later running on PHP 5.6 or higher.

This package can be installed using composer:

```
composer require Phumsoft/userstamps

```

Usage
-----

[](#usage)

Your model will need to include a `created_by` and `updated_by` column, defaulting to `null`.

If using the Laravel `SoftDeletes` trait, it will also need a `deleted_by` column.

The column type should match the type of the ID column in your user's table. In Laravel &lt;= 5.7 this defaults to `unsignedInteger`. For Laravel &gt;= 5.8 this defaults to `unsignedBigInteger`.

An example migration:

```
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
```

You can now load the trait within your model, and userstamps will automatically be maintained:

```
use Phumsoft\Userstamps\Userstamps;

class Foo extends Model {

    use Userstamps;
}
```

Optionally, should you wish to override the names of the `created_by`, `updated_by` or `deleted_by` columns, you can do so by setting the appropriate class constants on your model. Ensure you match these column names in your migration.

```
use Phumsoft\Userstamps\Userstamps;

class Foo extends Model {

    use Userstamps;

    const CREATED_BY = 'alt_created_by';
    const UPDATED_BY = 'alt_updated_by';
    const DELETED_BY = 'alt_deleted_by';
}
```

When using this trait, helper relationships are available to let you retrieve the user who created, updated and deleted (when using the Laravel `SoftDeletes` trait) your model.

```
$model->creator; // the user who created the model
$model->editor; // the user who last updated the model
$model->destroyer; // the user who deleted the model
```

Methods are also available to temporarily stop the automatic maintaining of userstamps on your models:

```
$model->stopUserstamping(); // stops userstamps being maintained on the model
$model->startUserstamping(); // resumes userstamps being maintained on the model
```

Workarounds
-----------

[](#workarounds)

This package works by hooking into Eloquent's model event listeners, and is subject to the same limitations of all such listeners.

When you make changes to models that bypass Eloquent, the event listeners won't be fired and userstamps will not be updated.

Commonly this will happen if bulk updating or deleting models, or their relations.

In this example, model relations are updated via Eloquent and userstamps **will** be maintained:

```
$model->foos->each(function ($item) {
    $item->bar = 'x';
    $item->save();
});
```

However in this example, model relations are bulk updated and bypass Eloquent. Userstamps **will not** be maintained:

```
$model->foos()->update([
    'bar' => 'x',
]);
```

As a workaroud to this issue two helper methods are available - `updateWithUserstamps` and `deleteWithUserstamps`. Their behaviour is identical to `update` and `delete`, but they ensure the `updated_by` and `deleted_by` properties are maintained on the model.

You generally won't have to use these methods, unless making bulk updates that bypass Eloquent events.

In this example, models are bulk updated and userstamps **will not** be maintained:

```
$model->where('name', 'foo')->update([
    'name' => 'bar',
]);
```

However in this example, models are bulk updated using the helper method and userstamps **will** be maintained:

```
$model->where('name', 'foo')->updateWithUserstamps([
    'name' => 'bar',
]);
```

License
-------

[](#license)

This open-source software is licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 83.3% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/66e3a7dcd1619d20157ccfbcb315d46dc9a7144dd3f3d6714db2f638167ad755?d=identicon)[silakchhum](/maintainers/silakchhum)

---

Top Contributors

[![dev4-ka](https://avatars.githubusercontent.com/u/92430300?v=4)](https://github.com/dev4-ka "dev4-ka (10 commits)")[![silakchhum](https://avatars.githubusercontent.com/u/57870782?v=4)](https://github.com/silakchhum "silakchhum (2 commits)")

### Embed Badge

![Health badge](/badges/phumsoft-userstamps/health.svg)

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

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

761.3M17](/packages/kartik-v-yii2-password)[vitalybaev/laravel5-dkim

Laravel 5/6 package for signing outgoing messages with DKIM.

3163.1k](/packages/vitalybaev-laravel5-dkim)

PHPackages © 2026

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