fetchTimelineData(); }); } /** * Clear timeline cache * * @return void */ public function clearCache(): void { Cache::forget(self::CACHE_KEY); } /** * Fetch timeline data from database * * @return array{groups: array, yearTabs: array} */ private function fetchTimelineData(): array { $groups = TimelineGroup::query() ->published() ->ordered() ->with([ 'years' => function ($query) { $query->published() ->ordered() ->with([ 'items' => function ($q) { $q->published()->ordered(); } ]); } ]) ->get(); // Transform to DTO format $groupsData = $groups->map(function ($group) { return [ 'title' => $group->title, 'subtitle' => $group->subtitle, 'years' => $group->years->map(function ($year) { return [ 'year' => $year->year, 'image' => $year->image ? asset('storage/' . $year->image) : asset('images/img-timeline.png'), 'items' => $year->items->map(function ($item) { return [ 'title' => $item->title, 'type' => $item->type, ]; })->values()->toArray(), ]; })->values()->toArray(), ]; })->values()->toArray(); // Extract all years for yearTabs $yearTabs = $groups->flatMap(function ($group) { return $group->years->pluck('year'); })->unique()->sort()->values()->reverse()->values()->toArray(); return [ 'groups' => $groupsData, 'yearTabs' => $yearTabs, ]; } }