Skip to content

Commit

Permalink
Update Auditable.php
Browse files Browse the repository at this point in the history
  • Loading branch information
MoamenEltouny authored Sep 12, 2021
1 parent 6bec506 commit 7f14395
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/Auditable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,24 @@ public function initializeAuditable()
*/
protected static function bootAuditable()
{
$user = Auth::id();

// Creating && Updating
self::saving(function ($item) use ($user) {
self::saving(function ($item) {
if ($item->timestamps)
if (!$item->getKey()) {
// Creating
$item->created_by = $user;
$item->created_by = auth()->id;
} else {
// Updating
$item->updated_by = $user;
$item->updated_by = auth()->id;
}
});

// Deleting
static::deleting(function ($item) use ($user) {
static::deleting(function ($item) {
if (is_bool($item->forceDeleting ?? null))
if (!$item->forceDeleting) {
// SOFT
$item->deleted_by = $user;
$item->deleted_by = auth()->id;
$item->save();
}
});
Expand Down

0 comments on commit 7f14395

Please sign in to comment.