diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 4948197..c9c9300 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -45,6 +45,9 @@ public function destroy(Account $account) { Gate::authorize('delete', $account); + $account->deleted_by = auth()->id(); + $account->save(); + $account->delete(); // soft delete return response()->json(['message' => 'Account deleted successfully'], 204); diff --git a/app/Http/Controllers/DepositController.php b/app/Http/Controllers/DepositController.php index f95fb77..9e62cdf 100644 --- a/app/Http/Controllers/DepositController.php +++ b/app/Http/Controllers/DepositController.php @@ -40,6 +40,9 @@ public function destroy(Deposit $deposit) { Gate::authorize('delete', $deposit); + $deposit->deleted_by = auth()->id(); + $deposit->save(); + $deposit->delete(); return response()->json(['message' => 'Deposited amount deleted'], 204); diff --git a/app/Observers/AccountObserver.php b/app/Observers/AccountObserver.php index e8c0d30..7f3396b 100644 --- a/app/Observers/AccountObserver.php +++ b/app/Observers/AccountObserver.php @@ -16,9 +16,4 @@ public function updating(Account $account) { $account->updated_by = auth()->id(); } - - public function deleting(Account $account): void - { - $account->deleted_by = auth()->id(); - } } diff --git a/app/Observers/DepositObserver.php b/app/Observers/DepositObserver.php index ee34246..63e42f1 100644 --- a/app/Observers/DepositObserver.php +++ b/app/Observers/DepositObserver.php @@ -15,9 +15,4 @@ public function updating(Deposit $deposit) { $deposit->updated_by = auth()->id(); } - - public function deleting(Deposit $deposit) - { - $deposit->deleted_by = auth()->id(); - } } diff --git a/tests/Feature/AccountTest.php b/tests/Feature/AccountTest.php index 8bd99cc..58b89be 100644 --- a/tests/Feature/AccountTest.php +++ b/tests/Feature/AccountTest.php @@ -75,6 +75,7 @@ public function test_user_can_delete_an_account() $this->assertSoftDeleted('accounts', [ 'id' => $account->id, + 'deleted_by' => $this->user->id, ]); } diff --git a/tests/Feature/DepositTest.php b/tests/Feature/DepositTest.php index a7c6209..8beed75 100644 --- a/tests/Feature/DepositTest.php +++ b/tests/Feature/DepositTest.php @@ -78,6 +78,7 @@ public function test_user_can_delete_deposit() $this->assertSoftDeleted('deposits', [ 'id' => $deposit->id, + 'deleted_by' => $this->user->id, ]); }