$themesData */ $themesData = $trans['themes']; $themes = collect($themesData) ->map(fn ($label, $value) => ['label' => $label, 'value' => $value]) ->values() ->all(); /** @var array $monthsData */ $monthsData = $trans['months']; $months = collect($monthsData) ->map(fn ($label, $value) => ['label' => $label, 'value' => $value]) ->values() ->all(); return Inertia::render('front/Pages/News', [ 'themes' => $themes, 'months' => $months, 'articles' => collect(NewsRepository::all()) ->map(fn ($a) => [ 'slug' => $a['slug'], 'title' => $a['title'], 'excerpt' => $a['excerpt'], 'date' => $a['date'], 'theme' => $a['theme'], 'month' => $a['month'], 'rotation' => $a['rotation'], ]) ->all(), ]); } public function show(string $slug): Response { $article = NewsRepository::findBySlug($slug); abort_if($article === null, 404); return Inertia::render('front/Pages/NewsDetail', [ 'slug' => $article['slug'], 'title' => $article['title'], 'meta' => $article['meta'] ?? null, 'type' => $article['type'], 'photos' => $article['photos'] ?? [], 'blocks' => $article['blocks'] ?? [], 'relatedArticles' => $this->getRelatedArticles($slug), ]); } /** * @return array> */ private function getRelatedArticles(string $excludeSlug): array { return collect(NewsRepository::all()) ->reject(fn ($a) => $a['slug'] === $excludeSlug) ->take(3) ->map(fn ($a) => [ 'slug' => $a['slug'], 'title' => $a['title'], 'excerpt' => $a['excerpt'], 'date' => $a['date'], 'rotation' => $a['rotation'], ]) ->values() ->all(); } }