*/ class NewsController extends Controller { /** * Shows all news posts in any category. * @return string */ public function index(): string { $categories = DB::table('news_categories')->get(); $news = new Category; return view('news/index', compact('categories', 'news')); } /** * Shows all posts in a specific category. * @param int $catId * @throws HttpRouteNotFoundException * @return string */ public function category(int $catId = 1): string { $category = new Category($catId); if ($category->id === 0) { throw new HttpRouteNotFoundException; } return view('news/category', compact('category')); } /** * Returns a news post. * @param int $id * @throws HttpRouteNotFoundException * @return string */ public function post(int $id = 0): string { // Create the post object $post = new Post($id); if (!$post->id) { throw new HttpRouteNotFoundException; } return view('news/post', compact('post')); } }