'All news', 'deals' => 'Deals', 'bundles' => 'Bundles', 'freebies' => 'Freebies', 'giveaways' => 'Giveaways', 'subscriptions' => 'Subscriptions', ]; public function index(string $cat = ''): string { if (! isset(self::CATEGORIES[$cat])) { throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); } $filter = $cat !== '' ? ['category' => $cat] : []; $posts = Mongo::collection('news') ->find($filter, ['sort' => ['date' => -1], 'limit' => 40]) ->toArray(); $data = [ 'pageTitle' => 'Video game news — GG.deals', 'posts' => $posts, 'cats' => self::CATEGORIES, 'active' => $cat, ]; return view('news', $data); } public function article(string $slug): string { $post = Mongo::collection('news')->findOne(['slug' => $slug]); if ($post === null) { throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); } $related = Mongo::collection('news') ->find( ['slug' => ['$ne' => $slug], 'category' => $post['category']], ['sort' => ['date' => -1], 'limit' => 4] ) ->toArray(); $data = [ 'pageTitle' => $post['title'] . ' — GG.deals', 'post' => $post, 'related' => $related, 'cats' => self::CATEGORIES, 'active' => $post['category'], ]; return view('news_article', $data); } }