user() ->bankingConnections() ->withCount('accounts') ->orderByDesc('created_at') ->get() ->each(function ($connection) { $connection->has_pending_accounts = $connection->hasPendingAccounts(); }); return Inertia::render('settings/connections', [ 'connections' => $connections, ]); } /** * Manually trigger a sync for a connection. */ public function sync(BankingConnection $connection): RedirectResponse { if ($connection->user_id !== auth()->id()) { abort(403); } if (! $connection->isActive()) { return back()->with('error', 'Connection is not active.'); } SyncBankingConnectionJob::dispatch($connection); return back()->with('success', 'Sync started. Transactions will be updated shortly.'); } /** * Revoke and delete a banking connection. */ public function destroy(DestroyConnectionRequest $request, BankingConnection $connection, BankingProviderInterface $provider): RedirectResponse { if ($connection->isEnableBanking() && $connection->session_id && $connection->isActive()) { try { $provider->revokeSession($connection->session_id); } catch (\Throwable $e) { Log::warning('Failed to revoke EnableBanking session', [ 'session_id' => $connection->session_id, 'error' => $e->getMessage(), ]); } } if ($request->boolean('delete_accounts')) { $connection->accounts->each(function ($account) { $account->transactions()->delete(); $account->balances()->delete(); $account->delete(); }); } else { $connection->accounts()->update([ 'banking_connection_id' => null, 'external_account_id' => null, ]); } $connection->update(['status' => BankingConnectionStatus::Revoked]); $connection->delete(); return redirect()->route('settings.connections.index') ->with('success', 'Banking connection disconnected.'); } }