|null */ protected ?Collection $findings = null; public static function canAccess(): bool { // Anyone who edits content benefits from seeing what is wrong with it. // Individual checks hide themselves behind their own permission. return Auth::user()?->can('panel.access') ?? false; } public static function getNavigationGroup(): string|UnitEnum|null { return __('panel.groups.administration'); } public static function getNavigationLabel(): string { return __('health.title'); } public function getTitle(): string|Htmlable { return __('health.title'); } public function getSubheading(): string|Htmlable|null { return __('health.subheading'); } /** * @return Collection */ public function findings(): Collection { return $this->findings ??= app(HealthReport::class)->runFor(Auth::user()); } /** * @return array */ protected function getHeaderActions(): array { return [ Action::make('refresh') ->label(__('health.actions.refresh')) ->icon('heroicon-o-arrow-path') ->color('gray') ->action(function (): void { $this->refreshFindings(); Notification::make() ->title(__('health.refreshed')) ->success() ->send(); }), ]; } public function refreshFindings(): void { // The badge is cached so that drawing it does not run ten checks on // every page of the panel; opening this page is the one moment we // definitely want fresh answers. app(HealthReport::class)->forget(Auth::user()); $this->findings = null; } /** * @return Collection */ public function problems(): Collection { return $this->findings()->filter(fn (Finding $f) => $f->severity->isProblem()); } /** * @return Collection */ public function passing(): Collection { return $this->findings()->reject(fn (Finding $f) => $f->severity->isProblem()); } public function hasErrors(): bool { return $this->problems()->contains(fn (Finding $f) => $f->severity === Severity::Error); } /** * A count in the sidebar, because a diagnostics page nobody opens * diagnoses nothing. */ public static function getNavigationBadge(): ?string { $problems = app(HealthReport::class)->problemCount(Auth::user()); return $problems > 0 ? (string) $problems : null; } public static function getNavigationBadgeColor(): ?string { return 'warning'; } }