@php
if (auth('platform_admin')->check()) {
$admin = auth('platform_admin')->user();
} elseif (auth('admin')->check()) {
$admin = auth('admin')->user();
} else {
$admin = null;
}
$adminRole = $admin ? $admin->role : null;
$tenantId = $admin ? $admin->tenant_id : null;
// Determine if user is platform owner
$isPlatformOwner = ($adminRole === 'platform_owner');
// Determine if user is tenant user
$isTenantUser = ($admin && !$isPlatformOwner && $tenantId !== null);
// Get tenant slug from request
$tenantSlug = request()->segment(1);
$tenant = $tenantSlug ? \App\Models\Tenant::where('slug', $tenantSlug)->first() : null;
// Check if tenant exists and is valid
$isValidTenant = $tenant && $tenant->exists;
// Get unread notification count for platform owner
if ($isPlatformOwner) {
$platformUnreadCount = \App\Models\PlatformNotification::where('is_read', false)->count();
} else {
$platformUnreadCount = 0;
}
// Get unread notification count for tenant users (company_admin, sales)
$tenantUnreadCount = 0;
if ($isTenantUser && $adminRole === 'company_admin') {
$tenantUnreadCount = \App\Models\UserNotification::where('is_read', false)->count();
}
// Check if tenant setup is complete
$tenantSetupComplete = false;
if ($isTenantUser && $tenantId) {
$tenantSetupComplete = \App\Models\TenantSetting::isSetupComplete($tenantId);
}
@endphp