reminder_months_before; } /** * @return array{total: int, valid: int, expiringSoon: int, expired: int} */ #[Computed] public function stats(): array { $threshold = today()->addMonths($this->months()); $total = Certificate::count(); $expired = Certificate::whereDate('expires_at', '<', today())->count(); $expiringSoon = Certificate::whereDate('expires_at', '>=', today()) ->whereDate('expires_at', '<=', $threshold) ->count(); return [ 'total' => $total, 'valid' => max(0, $total - $expired - $expiringSoon), 'expiringSoon' => $expiringSoon, 'expired' => $expired, ]; } /** * Certificates that are expired or expiring within the user's threshold, * soonest first — the actionable items. * * @return Collection */ #[Computed] public function attention(): Collection { return Certificate::with('category') ->whereDate('expires_at', '<=', today()->addMonths($this->months())) ->orderBy('expires_at') ->take(6) ->get(); } /** * @return Collection */ #[Computed] public function recent(): Collection { return Certificate::with('category')->latest()->take(5)->get(); } /** * @return Collection */ #[Computed] public function categories(): Collection { return Category::withCount('certificates') ->orderByDesc('certificates_count') ->orderBy('name') ->get(); } }; ?>
{{ __('Welcome back, :name', ['name' => auth()->user()->name]) }} {{ __('Here is the status of your certificates.') }}
{{ __('Add certificate') }}
@if ($this->stats['total'] === 0) {{ __('Get started') }} {{ __('No certificates yet') }} {{ __('Upload your first certificate to start tracking issue dates, expiry, and reminders.') }} {{ __('Add your first certificate') }} @else {{-- Stat tiles --}}
@php $tiles = [ ['label' => __('Total'), 'value' => $this->stats['total'], 'icon' => 'rectangle-stack', 'class' => 'text-zinc-800 dark:text-white', 'tile' => 'bg-gradient-to-br from-emerald-500 to-teal-600 text-white shadow-md shadow-emerald-500/25'], ['label' => __('Valid'), 'value' => $this->stats['valid'], 'icon' => 'check-badge', 'class' => 'text-emerald-600 dark:text-emerald-400', 'tile' => 'bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400'], ['label' => __('Expiring soon'), 'value' => $this->stats['expiringSoon'], 'icon' => 'clock', 'class' => 'text-amber-600 dark:text-amber-400', 'tile' => 'bg-amber-50 text-amber-600 dark:bg-amber-500/10 dark:text-amber-400'], ['label' => __('Expired'), 'value' => $this->stats['expired'], 'icon' => 'exclamation-triangle', 'class' => 'text-red-600 dark:text-red-400', 'tile' => 'bg-red-50 text-red-600 dark:bg-red-500/10 dark:text-red-400'], ]; @endphp @foreach ($tiles as $tile)
{{ $tile['label'] }}
{{ $tile['value'] }}
@endforeach
{{-- Needs attention --}}
{{ __('Needs attention') }} {{ __('View all') }}
@if ($this->attention->isEmpty())
{{ __('Nothing needs attention. All your certificates are up to date.') }}
@else
@foreach ($this->attention as $certificate) @php($status = $certificate->expiryStatus($this->stats['total'] ? auth()->user()->reminder_months_before : 1))
{{ $certificate->title }} {{ $certificate->category?->name ?? __('Uncategorized') }}
{{ $certificate->expires_at->format('M j, Y') }} {{ $certificate->expires_at->diffForHumans() }}
{{ $status->label() }}
@endforeach
@endif
{{-- By category --}}
{{ __('By category') }} {{ __('Manage') }}
@if ($this->categories->isEmpty()) {{ __('No categories yet.') }} @else
@foreach ($this->categories as $category)
{{ $category->name }} {{ $category->certificates_count }}
@endforeach
@endif
{{-- Recently added --}} {{ __('Recently added') }}
@foreach ($this->recent as $certificate) {{ $certificate->title }} {{ $certificate->created_at?->diffForHumans() }} @endforeach
@endif