argument('ids'))) ->map(fn (string $id): string => trim($id)) ->filter() ->unique() ->values(); if ($ids->isEmpty()) { $this->error('No connection IDs provided.'); return Command::FAILURE; } $deleteAccounts = $this->option('delete-accounts'); $connections = BankingConnection::query() ->with('accounts') ->whereIn('id', $ids) ->get(); $missing = $ids->diff($connections->pluck('id')); foreach ($missing as $id) { $this->warn("Connection not found: {$id}"); } if ($connections->isEmpty()) { $this->error('No matching banking connections found.'); return Command::FAILURE; } $disconnected = 0; foreach ($connections as $connection) { try { $disconnectBankingConnection->handle($connection, $deleteAccounts); $this->info("Disconnected connection {$connection->id} ({$connection->aspsp_name})."); $disconnected++; } catch (\Throwable $e) { $this->error("Failed to disconnect {$connection->id}: {$e->getMessage()}"); } } $this->info("Disconnected {$disconnected} of {$connections->count()} connection(s)."); return $missing->isEmpty() && $disconnected === $connections->count() ? Command::SUCCESS : Command::FAILURE; } }