PHPackages                             richan-fongdasen/eloquent-blameable - 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. richan-fongdasen/eloquent-blameable

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

richan-fongdasen/eloquent-blameable
===================================

Blameable behavior implementation for your Eloquent Model in Laravel

1.11.0(1y ago)34225.1k↓49.9%6[1 PRs](https://github.com/richan-fongdasen/eloquent-blameable/pulls)3MITPHPPHP ^8.0CI passing

Since Jul 13Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/richan-fongdasen/eloquent-blameable)[ Packagist](https://packagist.org/packages/richan-fongdasen/eloquent-blameable)[ Docs](https://github.com/richan-fongdasen/eloquent-blameable)[ RSS](/packages/richan-fongdasen-eloquent-blameable/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (10)Versions (21)Used By (3)

[![CI](https://github.com/richan-fongdasen/eloquent-blameable/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/richan-fongdasen/eloquent-blameable/actions/workflows/main.yml)[![codecov](https://camo.githubusercontent.com/348a34886d8d95c03a79237388ccd31b1465267f22e69ad5d32db1e8078ea48c/68747470733a2f2f636f6465636f762e696f2f67682f72696368616e2d666f6e67646173656e2f656c6f7175656e742d626c616d6561626c652f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/richan-fongdasen/eloquent-blameable)[![Total Downloads](https://camo.githubusercontent.com/139465c02db8884cc42f1fc6d36f67b198e74c1ebca05cb0482288e4f6b210f0/68747470733a2f2f706f7365722e707567782e6f72672f72696368616e2d666f6e67646173656e2f656c6f7175656e742d626c616d6561626c652f642f746f74616c2e737667)](https://packagist.org/packages/richan-fongdasen/eloquent-blameable)[![Latest Stable Version](https://camo.githubusercontent.com/b32ee93eea7ee54a6e515f0b7f08a9b4eb65378310ab77829fa1de489b4fb731/68747470733a2f2f706f7365722e707567782e6f72672f72696368616e2d666f6e67646173656e2f656c6f7175656e742d626c616d6561626c652f762f737461626c652e737667)](https://packagist.org/packages/richan-fongdasen/eloquent-blameable)[![License: MIT](https://camo.githubusercontent.com/f45d904953153ca304a2328243d2733e095eee13a631a1f390709885d41dd692/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2f6672616d65776f726b2f6c6963656e73652e737667)](https://opensource.org/licenses/MIT)

Eloquent Blameable
==================

[](#eloquent-blameable)

> Blameable behavior implementation for your Eloquent Model in Laravel

Synopsis
--------

[](#synopsis)

This package would help you to track the creator and updater of each database record. It would be done by filling the specified attributes with the current user ID automatically. By default, those attributes would be filled when you are saving the Eloquent Model object.

Table of contents
-----------------

[](#table-of-contents)

- [Setup](#setup)
- [Configuration](#configuration)
- [Usage](#usage)
- [License](#license)

Setup
-----

[](#setup)

Install the package via Composer :

```
$ composer require richan-fongdasen/eloquent-blameable
```

### Laravel version compatibility

[](#laravel-version-compatibility)

Laravel versionBlameable versionPHP version5.1.x1.0.x&gt;= 5.65.2.x - 5.4.x1.1.x - 1.2.x&gt;= 5.65.5.x - 5.8.x1.3.x&gt;= 7.06.x1.4.x&gt;= 7.27.x1.5.x&gt;= 7.28.x1.6.x&gt;= 7.39.x1.8.x&gt;= 8.010.x1.9.x - 1.10.x&gt;= 8.111.x - 12.x1.11.x&gt;= 8.013.x2.0.x&gt;= 8.3> If you are using Laravel version 5.5+ then you can skip registering the service provider in your Laravel application.

### Service Provider

[](#service-provider)

Add the package service provider in your `config/app.php`

```
'providers' => [
    // ...
    RichanFongdasen\EloquentBlameable\ServiceProvider::class,
];
```

Configuration
-------------

[](#configuration)

Publish configuration file using `php artisan` command

```
$ php artisan vendor:publish --provider="RichanFongdasen\EloquentBlameable\ServiceProvider"
```

The command above would copy a new configuration file to `/config/blameable.php`

```
return [

    /*
    |--------------------------------------------------------------------------
    | Authentication Guard
    |--------------------------------------------------------------------------
    |
    | Please specify your default authentication guard to be used by blameable
    | service. You can leave this to null if you're using the default Laravel
    | authentication guard.
    |
    | You can also override this value in model classes to use a different
    | authentication guard for your specific models.
    | IE: Some of your models can only be created / updated by specific users
    | who logged in from a specific authentication guard.
    |
    */

    'guard' => null,

    /*
    |--------------------------------------------------------------------------
    | User Model Definition
    |--------------------------------------------------------------------------
    |
    | Please specify a user model that should be used to setup `creator`
    | and `updater` relationship.
    |
    */

    'user' => \App\Models\User::class,

    /*
    |--------------------------------------------------------------------------
    | The `createdBy` attribute
    |--------------------------------------------------------------------------
    |
    | Please define an attribute to use when recording the creator
    | identifier.
    |
    */

    'createdBy' => 'created_by',

    /*
    |--------------------------------------------------------------------------
    | The `updatedBy` attribute
    |--------------------------------------------------------------------------
    |
    | Please define an attribute to use when recording the updater
    | identifier.
    |
    */

    'updatedBy' => 'updated_by',

    /*
    |--------------------------------------------------------------------------
    | The `deletedBy` attribute
    |--------------------------------------------------------------------------
    |
    | Please define an attribute to use when recording the user
    | identifier who deleted the record. This feature would only work
    | if you are using SoftDeletes in your model.
    |
    */

    'deletedBy' => 'deleted_by',
];
```

Usage
-----

[](#usage)

### Add some blameable attributes to your migrations

[](#add-some-blameable-attributes-to-your-migrations)

```
Schema::create('some_tables', function (Blueprint $table) {
    // ...

    $table->integer('created_by')->nullable();
    $table->integer('updated_by')->nullable();
    $table->integer('deleted_by')->nullable();

    // ...

    /**
     * You can also create foreign key constrains
     * for the blameable attributes.
     */
    $table->foreign('created_by')
        ->references('id')->on('users')
        ->onDelete('cascade');

    $table->foreign('updated_by')
        ->references('id')->on('users')
        ->onDelete('cascade');
});
```

### Attach Blameable behavior into your Model

[](#attach-blameable-behavior-into-your-model)

```
use Illuminate\Database\Eloquent\Model;
use RichanFongdasen\EloquentBlameable\BlameableTrait;

class Post extends Model
{
    use BlameableTrait;

    // ...
}
```

### Override default configuration using static property

[](#override-default-configuration-using-static-property)

```
    /**
     * You can override the default configuration
     * by defining this static property in your Model
     */
    protected static $blameable = [
        'guard' => 'customGuard',
        'user' => \App\Models\User::class,
        'createdBy' => 'user_id',
        'updatedBy' => null
    ];
```

### Override default configuration using public method

[](#override-default-configuration-using-public-method)

```
    /**
     * You can override the default configuration
     * by defining this method in your Model
     */
    public function blameable()
    {
        return [
            'guard' => 'customGuard',
            'user' => \App\Models\User::class,
            'createdBy' => 'user_id',
            'updatedBy' => null
        ];
    }
```

### Using Blameable Query Scopes

[](#using-blameable-query-scopes)

```
// Get all posts which have created by the given user id
Post::createdBy($userId)->get();

// Get all posts which have updated by the given user object
$user = User::findOrFail(1);
Post::updatedBy($user)->get();
```

### Accessing Creator / Updater Object

[](#accessing-creator--updater-object)

```
// Get the creator user object
Post::findOrFail($postId)->creator;

// Get the updater user object
Post::findOrFail($postId)->updater;
```

License
-------

[](#license)

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

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance71

Regular maintenance activity

Popularity45

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 87.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 ~146 days

Recently: every ~375 days

Total

20

Last Release

491d ago

Major Versions

0.2.0 → 1.0.02018-03-11

PHP version history (8 changes)0.1.0PHP ^5.5.9 || ^7.0

1.0.0PHP ^5.5.9 || ^7.0 || ^7.1.3

1.3.0PHP ^7.1.3

1.4.0PHP ^7.2

1.6.0PHP ^7.3

1.7.0PHP ^7.3|^8.0

1.8.0PHP ^7.4|^8.0

1.10.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5222595?v=4)[Richan Fongdasen](/maintainers/richan-fongdasen)[@richan-fongdasen](https://github.com/richan-fongdasen)

---

Top Contributors

[![richan-fongdasen](https://avatars.githubusercontent.com/u/5222595?v=4)](https://github.com/richan-fongdasen "richan-fongdasen (108 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![danielbehrendt](https://avatars.githubusercontent.com/u/283437?v=4)](https://github.com/danielbehrendt "danielbehrendt (2 commits)")[![andyundso](https://avatars.githubusercontent.com/u/7010698?v=4)](https://github.com/andyundso "andyundso (2 commits)")[![bakerkretzmar](https://avatars.githubusercontent.com/u/18192441?v=4)](https://github.com/bakerkretzmar "bakerkretzmar (2 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (2 commits)")[![juventus18](https://avatars.githubusercontent.com/u/1124513?v=4)](https://github.com/juventus18 "juventus18 (1 commits)")[![diegotibi](https://avatars.githubusercontent.com/u/25210612?v=4)](https://github.com/diegotibi "diegotibi (1 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![jure-knezovic](https://avatars.githubusercontent.com/u/67332841?v=4)](https://github.com/jure-knezovic "jure-knezovic (1 commits)")

---

Tags

blameableeloquenteloquent-modelslaravellaravel-5-packagelaraveleloquentlaravel-packageBlameable

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/richan-fongdasen-eloquent-blameable/health.svg)

```
[![Health](https://phpackages.com/badges/richan-fongdasen-eloquent-blameable/health.svg)](https://phpackages.com/packages/richan-fongdasen-eloquent-blameable)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M96](/packages/mongodb-laravel-mongodb)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k32.6M46](/packages/kirschbaum-development-eloquent-power-joins)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[glushkovds/phpclickhouse-laravel

Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel

2051.5M2](/packages/glushkovds-phpclickhouse-laravel)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.3M18](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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