This commit is contained in:
2025-12-28 12:16:05 +05:45
commit 7c46ec6731
3358 changed files with 467149 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Traits;
use Illuminate\Support\Facades\Auth;
trait CreatedUpdatedBy
{
public static function bootCreatedUpdatedBy()
{
// updating createdby and updatedby when model is created
static::creating(function ($model) {
if (!$model->isDirty('createdby')) {
$model->createdby = auth()->user()->id ?? 1;
}
if (!$model->isDirty('updatedby')) {
$model->updatedby = auth()->user()->id ?? 1;
}
});
// updating updatedby when model is updated
static::updating(function ($model) {
if (!$model->isDirty('updatedby')) {
$model->updatedby = auth()->user()->id ?? 1;
}
});
}
}