user(); if ($user->is_platform_admin) { return Inertia::render('dashboard', [ 'role' => SystemRole::MasterAdmin->value, 'tenant' => null, 'stats' => [ 'tenants' => Tenant::count(), 'activeTenants' => Tenant::where('is_active', true)->count(), 'users' => User::withoutGlobalScope('tenant')->where('is_platform_admin', false)->count(), 'activeLicenses' => License::withoutGlobalScope('tenant')->where('status', LicenseStatus::Active->value)->count(), 'installations' => DeploymentInstallation::withoutGlobalScope('tenant')->count(), ], ]); } $role = $user->hasRole(SystemRole::TenantAdmin->value) ? SystemRole::TenantAdmin->value : SystemRole::TenantUser->value; return Inertia::render('dashboard', [ 'role' => $role, 'tenant' => $user->tenant?->only(['id', 'name', 'slug', 'is_active']), 'installation' => DeploymentInstallation::query()->first()?->only(['deployment_type', 'domain', 'status', 'activated_at']), 'license' => License::query()->latest('created_at')->first()?->only(['plan', 'status', 'max_devices', 'max_users', 'expires_at', 'grace_until']), 'stats' => [ 'users' => User::count(), 'activeUsers' => User::where('is_active', true)->count(), 'devices' => Device::count(), 'canAddDevice' => $user->can('device.create'), ], ]); } }