visibleTo($user); $totalCount = (clone $base)->count(); $openCount = (clone $base)->whereNull('completed_at')->count(); $closedCount = (clone $base)->whereNotNull('completed_at')->count(); $criticalCount = (clone $base)->whereNull('completed_at')->whereHas('priority', static fn ($q) => $q->whereIn('slug', ['critical', 'urgent', 'high']))->count(); $closedPercent = $totalCount > 0 ? (int) round(($closedCount / $totalCount) * 100) : 0; $openPercent = $totalCount > 0 ? (int) round(($openCount / $totalCount) * 100) : 0; return view('helpdesk::livewire.dashboard-widget', [ 'totalCount' => $totalCount, 'openCount' => $openCount, 'closedCount' => $closedCount, 'criticalCount' => $criticalCount, 'closedPercent' => $closedPercent, 'openPercent' => $openPercent, 'recentCommits' => GitCommit::query()->with(['repository', 'ticket.user:id,name,email', 'ticket.owner:id,name,email', 'ticket.agent:id,name,email'])->latest('committed_at')->limit(6)->get(), 'recentTickets' => (clone $base)->with(['user:id,name,email', 'owner:id,name,email', 'agent:id,name,email', 'status', 'priority'])->latest('last_activity_at')->limit(5)->get(), ]); } }