From 97f1d591370c8015bfc320fe1b248251f4ff89b5 Mon Sep 17 00:00:00 2001 From: Wes Copeland Date: Wed, 5 Feb 2025 17:10:32 -0500 Subject: [PATCH] feat(game): add game_sets attach/detach actions to game audit logs (#3167) --- app/Models/GameSet.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/Models/GameSet.php b/app/Models/GameSet.php index 25be11f39e..ff96974571 100644 --- a/app/Models/GameSet.php +++ b/app/Models/GameSet.php @@ -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') { @@ -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') {