/** * Get all post in a category * @param $category * @return \Theme */ public function getCategories($category) { if (Categories::whereSlug($category)->exists()) { $category_db = Categories::whereSlug($category)->first(); if (!\Cache::has('posts-' . $category)) { $posts = Posts::whereCategoryId($category_db->id)->where('published_at', '!=', null)->orderBy('published_at', 'desc')->paginate(); \Cache::put('posts-' . $category, $posts, 5); } else { $posts = \Cache::get('posts-' . $category); } return \Theme::view('blog.category', ['posts' => $posts, 'category' => $category_db]); } else { return abort(404); } }