Skip to content

A simple trait to add to models that auto fill "created_by" and "updated_by" values.

License

Notifications You must be signed in to change notification settings

ritta-ibrahim/created-by-and-updated-by-laravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

created-by-and-updated-by-laravel

A simple trait to add to models that auto fill "created_by" and "updated_by" values.

Usage

  1. Add the BlamableTrait.php file to the "App\Traits" directory.
  2. Add the columns to the table:
$table->unsignedBigInteger('created_by')->nullable();
$table->unsignedBigInteger('updated_by')->nullable();
  1. Use the trait in the model:
use App\Traits\BlamableTrait;

class Category extends Model
{
    use HasFactory, BlamableTrait;
}

Now whenever you save a new record without manually filling created_by and updated_by, the trait will automatically fill the fields with current auth user id, or just leave it null if no user logged in. And whenever you update a record the trait will fill only the updated_by column.

License

This code is licensed under the MIT license.

About

A simple trait to add to models that auto fill "created_by" and "updated_by" values.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages