PHPackages                             rmasters/culpa - 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. rmasters/culpa

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

rmasters/culpa
==============

Adds Blameable support to Eloquent models in Laravel

v0.6.0(12y ago)242.2k9[4 issues](https://github.com/rmasters/culpa/issues)[3 PRs](https://github.com/rmasters/culpa/pulls)MITPHPPHP &gt;=5.3.0

Since Jul 12Pushed 10y ago3 watchersCompare

[ Source](https://github.com/rmasters/culpa)[ Packagist](https://packagist.org/packages/rmasters/culpa)[ Docs](https://github.com/rmasters/culpa)[ RSS](/packages/rmasters-culpa/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (5)Dependencies (7)Versions (7)Used By (0)

Culpa [![Latest Stable Version](https://camo.githubusercontent.com/c45b092c13e88e452fca3e83463056a54a810a61ef7cce94bf4d3ab587c0caef/68747470733a2f2f706f7365722e707567782e6f72672f726d6173746572732f63756c70612f762f737461626c652e706e67)](https://packagist.org/packages/rmasters/culpa) [![master](https://camo.githubusercontent.com/a186dff0f8404c2287f75a4ffd65dfd1567babe4d76aa356bf2142c74ac780f0/68747470733a2f2f7472617669732d63692e6f72672f726d6173746572732f63756c70612e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/rmasters/culpa) [![Coverage Status](https://camo.githubusercontent.com/e92a03412719e93abe51cf33086e3abb56a46343c3f79f4912dc6e5effb8ec9b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f726d6173746572732f63756c70612f62616467652e706e67)](https://coveralls.io/r/rmasters/culpa) [![Dependency Status](https://camo.githubusercontent.com/4e303117d360ef0d49a3208feff579393dc4e5263d364c836fb773db96e43738/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3531653031303236393034313036303030323030303162622f62616467652e706e67)](https://www.versioneye.com/user/projects/51e0102690410600020001bb)
===========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#culpa----)

Blameable extension for Laravel's Eloquent ORM models. This extension automatically adds references to the authenticated user when creating, updating or soft-deleting a model.

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

[](#installation)

This package works with PHP 5.3 and above, but includes traits to make it easier to use on PHP 5.4+.

To install the package in your project:

1. Add to the require section of your `composer.json`: `"rmasters/culpa": "dev-master"`,
2. Run `composer update`,
3. Add to the `providers` list in config/app.php: `"Culpa\CulpaServiceProvider"`,
4. Publish the configuration to your application: `artisan config:publish rmasters/culpa`

Usage
-----

[](#usage)

You can add auditable fields on a per-model basis by adding a protected property and a model observer. The property `$blameable` contains events you wish to record - at present this is restricted to created, updated and deleted - which function the same as Laravel's timestamps.

```
class Comment extends Eloquent {

    protected $blameable = array('created', 'updated', 'deleted');

```

- On create, the authenticated user will be set in `created_by_id`,
- On create and update, the authenticated user will be set in `updated_by_id`,
- Additionally, if the model is soft-deletable, the authenticated user will be set in `deleted_by_id`.

To activate the automatic updating of these fields, you need to add the model observer to this model:

```
class Comment extends Eloquent {

    // ...

}
Comment::observe(new Culpa\BlameableObserver);

```

The names of the columns used can be changed by passing an associative array of event names to columns:

```
protected $blameable = array(
    'created' => 'author_id',
    'updated' => 'revised_by_id'
);

```

You will need to add these fields to your migrations for the model (unsigned integer fields with foreign keys as appropriate), and add accessors to your model:

```
class Comment extends Eloquent {

    public function createdBy() {
        return $this->belongsTo('User');
    }

```

}

If you're using PHP 5.4 or above, you can take advantage of the provided traits to add these methods automatically (`Culpa\CreatedBy`, `Culpa\UpdatedBy`, `Culpa\DeletedBy`).

### Changing the user source

[](#changing-the-user-source)

The `culpa::users.active_user` config should yield a function that returns a user id, or null if there is no user authenticated.

```
'users' => [

    // The default implementation:
    'active_user' => function() {
        return Auth::check() ? Auth::user()->id : null;
    }

    // or, for Sentry2 integration:
    'active_user' => function() {
        return Sentry::check() ? Sentry::getUser()->id : null;
    }

```

### Changing the user class

[](#changing-the-user-class)

By default, the fields will relate to `User` - this can be configured as so in the package configuration file:

```
'users' => array(

    // Use the Sentry2 user model
    'classname' => 'Cartalyst\Sentry\Users\Eloquent\User'

)

```

License
-------

[](#license)

Culpa is released under the [MIT License](LICENSE).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98% 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 ~27 days

Total

5

Last Release

4579d ago

PHP version history (2 changes)0.2.0PHP &gt;=5.4.0

0.3.0PHP &gt;=5.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/32d44b8b36e16d8e06b489556da46a1e839726b0d6003fcd2642a3c94c8069f7?d=identicon)[rmasters](/maintainers/rmasters)

---

Top Contributors

[![rmasters](https://avatars.githubusercontent.com/u/34284?v=4)](https://github.com/rmasters "rmasters (48 commits)")[![carnevalle](https://avatars.githubusercontent.com/u/54747?v=4)](https://github.com/carnevalle "carnevalle (1 commits)")

---

Tags

laravelBlameablecreated\_by

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rmasters-culpa/health.svg)

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[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)[wildside/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.

7511.7M13](/packages/wildside-userstamps)[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)

PHPackages © 2026

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