From c54bce1ca77a97ac5798213ca2bd39d7de74f3b0 Mon Sep 17 00:00:00 2001 From: isaacclad Date: Fri, 19 Jun 2026 10:16:52 +0000 Subject: [PATCH] Hide the current page link in the unified profile dropdown. Skip Home, account, and admin menu items when the user is already on that destination. Co-authored-by: Cursor --- app/Support/UserProfileMenu.php | 77 ++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/app/Support/UserProfileMenu.php b/app/Support/UserProfileMenu.php index 8af3f5d..3228d49 100644 --- a/app/Support/UserProfileMenu.php +++ b/app/Support/UserProfileMenu.php @@ -7,7 +7,12 @@ use Illuminate\Support\Facades\Route; class UserProfileMenu { - /** @return list> */ + /** + * Standard signed-in profile links for Ladill product apps. + * Not used by Ladill Mail (mail.ladill.com) — that app keeps a mailbox-specific menu. + * + * @return list> + */ public static function items(?Authenticatable $user = null): array { $user ??= auth()->user(); @@ -25,19 +30,29 @@ class UserProfileMenu ['label' => 'Dashboard', 'path' => 'dashboard'], ['label' => 'Billing', 'path' => 'billing'], ] as $link) { + $href = self::platformUrl($link['host'] ?? 'account', $link['path']); + + if (self::isCurrentMenuLink($link, $href)) { + continue; + } + $items[] = [ 'type' => 'link', 'label' => $link['label'], - 'href' => self::platformUrl($link['host'] ?? 'account', $link['path']), + 'href' => $href, ]; } if (self::userIsAdmin($user)) { - $items[] = [ - 'type' => 'link', - 'label' => 'Admin', - 'href' => self::platformUrl('account', 'admin'), - ]; + $adminHref = self::platformUrl('account', 'admin'); + + if (! self::isCurrentMenuLink(['path' => 'admin', 'host' => 'account'], $adminHref)) { + $items[] = [ + 'type' => 'link', + 'label' => 'Admin', + 'href' => $adminHref, + ]; + } } if (Route::has('logout')) { @@ -74,6 +89,54 @@ class UserProfileMenu return self::absoluteUrl((string) config('app.account_domain'), $path); } + /** + * Hide a menu link when the signed-in user is already on that destination. + * + * @param array{label?: string, path?: string, host?: string} $link + */ + private static function isCurrentMenuLink(array $link, string $href): bool + { + if (app()->runningInConsole() && ! app()->runningUnitTests()) { + return false; + } + + $request = request(); + if (! $request) { + return false; + } + + $linkHost = strtolower((string) parse_url($href, PHP_URL_HOST)); + $currentHost = strtolower($request->getHost()); + + if ($linkHost === '' || $linkHost !== $currentHost) { + return false; + } + + $currentPath = trim($request->getPathInfo(), '/'); + $targetPath = trim((string) parse_url($href, PHP_URL_PATH), '/'); + + if (($link['host'] ?? 'account') === 'home') { + return $currentPath === ''; + } + + if (($link['path'] ?? '') === 'dashboard') { + return in_array($currentPath, ['dashboard', 'account'], true) + || ($targetPath !== '' && self::pathMatchesSection($currentPath, $targetPath)); + } + + return self::pathMatchesSection($currentPath, $targetPath); + } + + private static function pathMatchesSection(string $currentPath, string $targetPath): bool + { + if ($targetPath === '') { + return $currentPath === ''; + } + + return $currentPath === $targetPath + || str_starts_with($currentPath, $targetPath.'/'); + } + private static function absoluteUrl(string $domain, string $path = ''): string { $base = 'https://'.trim($domain, '/');