zing/laravel-eloquent-blameable

Track the creator and updater for Laravel eloquent

3.3.0 2024-03-18 14:37 UTC

This package is auto-updated.

Last update: 2024-11-07 15:21:09 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Requirements

Require Laravel Eloquent Blameable using Composer:

composer require zing/laravel-eloquent-blameable

Usage

<?php

use Illuminate\Database\Eloquent\Model;
use Zing\LaravelEloquentBlameable\Blameable;

class Content extends Model
{
    use Blameable;
}

Custom creator key name or updater key name

<?php

use Illuminate\Database\Eloquent\Model;
use Zing\LaravelEloquentBlameable\Blameable;

class Content extends Model
{
    use Blameable;

    public function getCreatorKeyName(): string
    {
        return 'created_by';
    }

    public function getUpdaterKeyName(): string
    {
        return 'updated_by';
    }
}

Model without updater

<?php

use Illuminate\Database\Eloquent\Model;
use Zing\LaravelEloquentBlameable\Blameable;

class Content extends Model
{
    use Blameable;

    public function getCreatorKeyName(): string
    {
        return 'created_by';
    }

    public function getUpdaterKeyName(): ?string
    {
        return null;
    }
}

License

Laravel Eloquent Blameable is an open-sourced software licensed under the MIT license.