published() ->latest('created_at') ->latest('id') ->paginate(9) ->withQueryString() ->through(fn (News $item): array => $this->summary($item)); return Inertia::render('News/Index', [ ...$this->portalProps($request), 'articles' => $articles, ]); } public function show(Request $request, News $news): Response { abort_unless($news->is_published, 404); $moreNews = News::query() ->published() ->where('id', '!=', $news->id) ->latest('created_at') ->latest('id') ->limit(3) ->get() ->map(fn (News $item): array => $this->summary($item)) ->values() ->all(); return Inertia::render('News/Show', [ ...$this->portalProps($request), 'article' => [ ...$this->summary($news), 'body' => $news->body, 'canonical_url' => route('news.show', $news), 'back_url' => route('news.index'), ], 'moreNews' => $moreNews, ]); } /** * @return array */ private function summary(News $news): array { return [ 'id' => $news->id, 'title' => $news->title, 'excerpt' => Str::limit(trim(strip_tags($news->body)), 200), 'date' => $news->created_at?->locale(app()->getLocale())->isoFormat('D MMMM YYYY'), 'image_url' => $news->image_url, 'url' => route('news.show', $news), ]; } }