Skip to content

Commit

Permalink
Capture the log meta for what was changed
Browse files Browse the repository at this point in the history
Signed-off-by: snipe <[email protected]>
  • Loading branch information
snipe committed Jul 11, 2024
1 parent 58bc844 commit 5108b1f
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions app/Observers/ConsumableObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,26 @@ class ConsumableObserver
*/
public function updated(Consumable $consumable)
{
$logAction = new Actionlog();
$logAction->item_type = Consumable::class;
$logAction->item_id = $consumable->id;
$logAction->created_at = date('Y-m-d H:i:s');
$logAction->user_id = Auth::id();
$logAction->logaction('update');

$changed = [];

foreach ($consumable->getRawOriginal() as $key => $value) {
// Check and see if the value changed
if ($consumable->getRawOriginal()[$key] != $consumable->getAttributes()[$key]) {
$changed[$key]['old'] = $consumable->getRawOriginal()[$key];
$changed[$key]['new'] = $consumable->getAttributes()[$key];
}
}

if (count($changed) > 0) {
$logAction = new Actionlog();
$logAction->item_type = Consumable::class;
$logAction->item_id = $consumable->id;
$logAction->created_at = date('Y-m-d H:i:s');
$logAction->user_id = Auth::id();
$logAction->log_meta = json_encode($changed);
$logAction->logaction('update');
}
}

/**
Expand Down

0 comments on commit 5108b1f

Please sign in to comment.