Skip to content

Commit

Permalink
feat: using transaction() in the HandleDeactivationRequests command
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadmp97 committed Sep 11, 2023
1 parent 853dd7c commit 4af8ae4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/Console/Commands/HandleDeactivationRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\DeactivationRequest;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class HandleDeactivationRequests extends Command
{
Expand All @@ -17,8 +18,9 @@ public function handle()
$userIds = DeactivationRequest::query()
->where('created_at', '<', now()->subDays(10))
->pluck('user_id');

$users = User::query()

DB::transaction(function () use ($userIds) {
$users = User::query()
->whereIn('id', $userIds)
->get();

Expand All @@ -29,6 +31,7 @@ public function handle()
DeactivationRequest::query()
->whereIn('user_id', $userIds)
->delete();
});

return $this->comment('Done!');
}
Expand Down

0 comments on commit 4af8ae4

Please sign in to comment.