@php
// Determine active guard (priority: explicit $guard, authenticated guards, path heuristic)
$g = $guard ?? null;
if(!$g) {
if(auth('admin')->check()) {
$g = 'admin';
} elseif(auth('state')->check()) {
$g = 'state';
} elseif(auth()->check()) {
$g = 'web';
} else {
// Path based heuristic if unauthenticated
if(request()->is('admin') || request()->is('admin/*')) {
$g = 'admin';
} elseif(request()->is('state') || request()->is('state/*')) {
$g = 'state';
} else {
$g = 'web';
}
}
}
// Determine if user is logged in for that guard
$loggedIn = match($g) {
'admin' => auth('admin')->check(),
'state' => auth('state')->check(),
default => auth()->check(),
};
// Compute target route (dashboard if logged in else login)
$targetRoute = $loggedIn ? match($g) {
'admin' => 'admin.dashboard',
'state' => 'state.dashboard',
default => 'dashboard',
} : match($g) {
'admin' => 'admin.login',
'state' => 'state.login',
default => 'login',
};
$labelBase = $loggedIn ? 'Dashboard' : 'Login';
$guardLabel = $g === 'web' ? 'User' : ucfirst($g);
$linkLabel = $label ?? ($guardLabel.' '.$labelBase);
$btnClass = $buttonClass ?? 'btn btn-lg btn-primary';
// Build icon HTML. Accept either raw HTML (e.g., '')
// or a Font Awesome class string (e.g., 'fas fa-home').
$iconHtml = '';
if (isset($icon)) {
$iconStr = trim((string)$icon);
if ($iconStr !== '') {
if (str_contains($iconStr, '<')) {
// Treat as raw HTML
$iconHtml = $iconStr;
} else {
// Treat as class name(s)
$iconHtml = '';
}
}
}
@endphp
{!! $iconHtml !!} {{ $linkLabel }}