argument('email'); $user = User::withTrashed()->where('email', $email)->first(); if (! $user) { $this->error("User with email '{$email}' not found."); return self::FAILURE; } $accountIds = $user->accounts()->whereNull('banking_connection_id')->pluck('id'); if ($accountIds->isEmpty()) { $this->info("User '{$email}' has no non-connected accounts."); return self::SUCCESS; } $transactionCount = Transaction::withTrashed()->whereIn('account_id', $accountIds)->count(); $balanceCount = AccountBalance::query()->whereIn('account_id', $accountIds)->count(); if (! $this->confirm("Delete {$transactionCount} transaction(s) and {$balanceCount} balance(s) across {$accountIds->count()} non-connected account(s) of '{$user->email}'?")) { $this->info('Deletion cancelled.'); return self::SUCCESS; } DB::transaction(function () use ($accountIds): void { // forceDelete purges soft-deleted transactions too; balances have no SoftDeletes, so delete() is already a hard delete. Transaction::query()->whereIn('account_id', $accountIds)->forceDelete(); AccountBalance::query()->whereIn('account_id', $accountIds)->delete(); }); $this->info("Deleted {$transactionCount} transaction(s) and {$balanceCount} balance(s) for '{$user->email}'."); return self::SUCCESS; } }