Skip to content

Commit

Permalink
feat(game): add game_sets attach/detach actions to game audit logs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wescopeland authored Feb 5, 2025
1 parent 1287a35 commit 97f1d59
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/Models/GameSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ public static function boot()
])
->event('pivotAttached')
->log('pivotAttached');

// Log the attachment on each game model.
foreach ($attachedGames as $game) {
$attribute = $model->type === GameSetType::Hub ? 'hubs' : 'similarGames';

activity()->causedBy($user)->performedOn($game)
->withProperty('old', [$attribute => null])
->withProperty('attributes', [$attribute => [
'id' => $model->id,
'title' => $model->title,
]])
->event('pivotAttached')
->log('pivotAttached');
}
}

if ($relationName === 'parents') {
Expand Down Expand Up @@ -121,6 +135,20 @@ public static function boot()
->withProperty('attributes', [$relationName => null])
->event('pivotDetached')
->log('pivotDetached');

// Log the detachment on each game model.
foreach ($detachedGames as $game) {
$attribute = $model->type === GameSetType::Hub ? 'hubs' : 'similarGames';

activity()->causedBy($user)->performedOn($game)
->withProperty('old', [$attribute => [
'id' => $model->id,
'title' => $model->title,
]])
->withProperty('attributes', [$attribute => null])
->event('pivotDetached')
->log('pivotDetached');
}
}

if ($relationName === 'parents') {
Expand Down

0 comments on commit 97f1d59

Please sign in to comment.