IMMREX7
<?php
namespace App\Traits;
trait AutoUpdateUserColumns {
protected static function boot() {
parent::boot();
static::creating(function($model) {
if (!auth()->guest() && auth('web')->user()) {
$model->created_by = auth('web')->user()->idUser;
}
if (method_exists($model, 'saveAttributes')) {
$model->saveAttributes();
}
});
static::updating(function($model) {
if (!auth()->guest() && auth('web')->user()) {
$model->updated_by = auth('web')->user()->idUser;
}
});
}
public function user_created() {
return $this->belongsTo(\App\User::class, 'created_by', 'idUser');
}
public function user_modified() {
return $this->belongsTo(\App\User::class, 'updated_by', 'idUser');
}
}
Copyright © 2021 -