for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace TobyMaxham\Helper\Models\Logs;
use App;
use Auth;
/**
* @author Tobias Maxham <[email protected]>
*/
trait ChangeByUser
{
* automatically boot laravel model traits...
public static function bootChangeByUser()
static::creating(function ($model) {
if (App::runningInConsole() || ! Auth::check()) {
return true;
}
if ($model->getCreatedByColumn()) {
$model->{$model->getUpdatedByColumn()} = Auth::user()->getKey();
if ($model->getUpdatedByColumn()) {
});
static::updating(function ($model) {
static::deleting(function ($model) {
if ($model->getDeletedByColumn()) {
$model->{$model->getDeletedByColumn()} = Auth::user()->getKey();
public function getCreatedByColumn(): string
return 'created_by';
public function getUpdatedByColumn(): string
return 'updated_by';
public function getDeletedByColumn(): string
return 'deleted_by';