@php use App\Models\Document; use App\Models\NewsEvent; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Storage; $headerAboutPages = require resource_path('data/frontend-v3-about.php'); $headerFlagshipProjects = $headerAboutPages['flagship-projects']['projects'] ?? []; $topbarLocale = App::getLocale(); $topbarLocalized = static function ($record, string $field) use ($topbarLocale): ?string { $localizedField = $field . '_' . $topbarLocale; $fallbackField = $field . '_en'; return filled($record->{$localizedField} ?? null) ? $record->{$localizedField} : $record->{$fallbackField} ?? null; }; $topbarDate = static fn($record) => $record->published_at ?: $record->created_at; $topbarIsNew = static fn($record): bool => filled($topbarDate($record)) && $topbarDate($record)->greaterThanOrEqualTo(now()->subWeek()); $topbarAnnouncements = NewsEvent::query() ->where('status', 'published') ->where('type', 'announcement') ->orderByRaw('COALESCE(published_at, created_at) DESC') ->orderByDesc('id') ->limit(5) ->get(); $topbarNotices = Document::query() ->with('file') ->where('status', 'published') ->where('type', 'notice') ->orderByRaw('COALESCE(published_at, created_at) DESC') ->orderByDesc('id') ->limit(5) ->get(); $topbarNotifications = $topbarAnnouncements ->concat($topbarNotices) ->sortByDesc(fn($notification) => $topbarDate($notification)?->getTimestamp() ?? 0) ->take(5) ->values(); $topbarTenders = Document::query() ->with('file') ->where('status', 'published') ->where('type', 'tender') ->orderByRaw('COALESCE(published_at, created_at) DESC') ->orderByDesc('id') ->limit(5) ->get(); try { $headerEvents = \App\Models\Event::query() ->published() ->latestFirst() ->limit(10) ->get(['id', 'slug', 'title_en', 'title_as']); } catch (\Throwable $exception) { // The menu must never take the whole site down (e.g. events table not migrated yet). report($exception); $headerEvents = collect(); } $topbarNotificationUrl = static function ($notification): string { if (! $notification instanceof Document) { return url('/news-announcements/'.$notification->slug); } $asset = $notification->file; if (! $asset?->file_path) { return url('/tenders'); } $path = $asset->file_path; if (str($path)->startsWith(['http://', 'https://', '/'])) { return $path; } if (str($path)->startsWith(['storage/', 'images/'])) { return asset($path); } return ($asset->disk ?: 'public') === 'public' ? asset('storage/'.$path) : Storage::disk($asset->disk)->url($path); }; @endphp