where('type', StaticPageType::we_move)->first(); $sectionModels = Section::query()->where('page_id', $staticPageModel->id)->get(); $newsModels = News::query()->where('published', true)->orderBy('publish_at', 'DESC')->simplePaginate(2); return view('fo.pages.news.index', \compact('staticPageModel', 'sectionModels', 'newsModels')); } /** * Display a news articles * * @param \App\Models\News $news * @return \Illuminate\Contracts\View\View */ public function show(News $news): \Illuminate\Contracts\View\View { // Get only id from published news. $publishedNews = News::query()->where('published', true)->orderBy('publish_at', 'DESC')->get()->pluck('id'); // Search the position of the current news id. $positionId = \array_search($news->id, $publishedNews->toArray()); // Check if it's the last position. $nextPositionId = ($positionId === count($publishedNews) - 1) ? 0 : intval($positionId) + 1 ; // Find the next news from the id. $nextNews = News::query()->where('id', $publishedNews[$nextPositionId])->firstOrFail(); // Check if it's the first position. $prevPositionId = ($positionId === 0) ? count($publishedNews) - 1 : intval($positionId) - 1 ; // Find the next news from the id. $prevNews = News::query()->where('id', $publishedNews[$prevPositionId])->firstOrFail(); return view('fo.pages.news.show', \compact('news', 'nextNews', 'prevNews')); } }