PHPackages                             malhal/laravel-createdby - 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. [Framework](/categories/framework)
4. /
5. malhal/laravel-createdby

ActiveLibrary[Framework](/categories/framework)

malhal/laravel-createdby
========================

A trait that adds createdBy and updatedBy user relations to your models

v1.0.0(9y ago)311302[1 issues](https://github.com/malhal/Laravel-CreatedBy/issues)MITPHPPHP &gt;=5.6.4

Since Sep 19Pushed 9y ago1 watchersCompare

[ Source](https://github.com/malhal/Laravel-CreatedBy)[ Packagist](https://packagist.org/packages/malhal/laravel-createdby)[ RSS](/packages/malhal-laravel-createdby/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Laravel-CreatedBy
=================

[](#laravel-createdby)

A trait that adds createdBy and updatedBy user relations to your models.

First either update your database or add this to a migration for each model:

```
$table->unsignedInteger('created_by_id');
$table->unsignedInteger('updated_by_id');
$table->foreign('created_by_id')
    ->references('id')->on('users')
    ->onDelete('cascade');
$table->foreign('updated_by_id')
    ->references('id')->on('users')
    ->onDelete('cascade');

```

Finally in your model use:

```
use CreatedBy;

```

Now whenever a model is created or updated the createdBy and updatedBy relations will be automatically updated.

Unfortunately you shouldn't use this trait on the User model when using auto-increment keys, this is due to the limitation in MySQL that a field cannot reference the currently being inserted ID. However you can still make use of the [Laravel-CreatedByPolicy](https://github.com/malhal/Laravel-CreatedByPolicy) with the workaround explained in that project. If you are using UUIDs for keys then this problem won't happen.

There are some extra scope features, e.g.

To add the join to retrieve the user info from the user table:

```
$query->withCreatedBy()
$query->withUpdatedBy()

```

To query based on a user:

```
$query->whereCreatedBy($user)

```

To temporarily disable updates on a save:

```
$model->saveWithoutCreatedBy();

```

If you would like to utilise this trait as part of a simple secuity model check out the extension of this trait [Laravel-CreatedByPolicy](https://github.com/malhal/Laravel-CreatedByPolicy).

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

[](#installation)

[PHP](https://php.net) 5.6.4+ and [Laravel](http://laravel.com) 5.3+ are required.

To get the latest version of Laravel CreatedBy, simply require the project using [Composer](https://getcomposer.org):

```
$ composer require malhal/laravel-createdby dev-master
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

3571d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/916912?v=4)[Malcolm Hall](/maintainers/malhal)[@malhal](https://github.com/malhal)

---

Top Contributors

[![malhal](https://avatars.githubusercontent.com/u/916912?v=4)](https://github.com/malhal "malhal (25 commits)")[![sarfraznawaz2005](https://avatars.githubusercontent.com/u/201788?v=4)](https://github.com/sarfraznawaz2005 "sarfraznawaz2005 (1 commits)")

---

Tags

frameworklaravelusermodelsMalcolm HallmalhalCreatedByupdatedByLaravel CreatedBy

### Embed Badge

![Health badge](/badges/malhal-laravel-createdby/health.svg)

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

###  Alternatives

[laravel/laravel

The skeleton application for the Laravel framework.

84.6k62.4M1.0k](/packages/laravel-laravel)[malhal/laravel-geographical

Easily add longitude and latitude columns to your records and use inherited functionality for calculating distances

283391.5k](/packages/malhal-laravel-geographical)[unopim/unopim

UnoPim Laravel PIM

10.5k2.2k](/packages/unopim-unopim)[nasirkhan/laravel-starter

A CMS like modular Laravel starter project.

1.4k2.7k](/packages/nasirkhan-laravel-starter)[codewithdennis/larament

Larament is a time-saving starter kit to quickly launch Laravel 13.x projects. It includes FilamentPHP 5.x pre-installed and configured, along with additional tools and features to streamline your development workflow.

3911.7k](/packages/codewithdennis-larament)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11914.4k42](/packages/kompo-kompo)

PHPackages © 2026

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