Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Blameable Laravel Package

digitalcloud/laravel-blameable

View on GitHub
Deep Wiki
Context7

Latest Stable Version Total Downloads

Laravel Blameable.

This package allow you to track the creator, updater and deleter of eloquent models.

Installation

You can install the package via composer:


composer require digitalcloud/laravel-blameable

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just add the service provider in config/app.php file:


    'providers' => [
        DigitalCloud\Blameable\BlameableServiceProvider::class,
    ];

You can publish the config file with:


    php artisan vendor:publish --provider="DigitalCloud\Blameable\BlameableServiceProvider" --tag="config"

When published, the config/blameable.php config file contains:

<?php

return [
    'column_names' => [
        'createdByAttribute' => 'created_by',
        'updatedByAttribute' => 'updated_by',
        'deletedByAttribute' => 'deleted_by',
    ],
     'models' => [
         'user' => \App\User::class
     ]
];

You can update the columns names in this file, or you can stack with default names. If you are not using the default laravel App\User model you need to provide the model class.

Usage Example

First, you need to add the DigitalCloud\Blameable\Traits\Blameable trait to your model(s). For example:

<?php

namespace App;

use DigitalCloud\Blameable\Traits\Blameable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Blameable;
}

Then, you need to make sure that the database table for the model has the required columns. Luckily we provide two ways to do this task:

  • By using console command and provide the model which you need to add columns:

      php artisan blameable:add-blameable-columns App\Post
    
  • By calling addBlameableColumns() on the model uses DigitalCloud\Blameable\Traits\Blameable trait:

      \App\Post::addBlameableColumns();
    

By using DigitalCloud\Blameable\Traits\Blameable in your model, the package will fill those columns automatically after creating, updating and deleting the model.

Relations

To get the creator/editor instance you can use:

$post = \App\Post::find(1);
$creator = $post->creator;
$editor = $post->editor;
$deletor = $post->deletor;

Note:

The package allow you to add blame columns to your migrations, using blameable() functions, for example:


    Schema::table($table, function (Blueprint $table) {
        // this will add created_by, updated_by and updated_by columns on your table.
        $table->blameable();
    });
            
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament