take(12)->get()); } /** * Load all the articles for a given topics * * @param mixed $topic */ public function show(Topic $topic) { $currentPage = request()->get('page',1); return Cache::remember($topic->slug. '_'.$currentPage, 300, function () use ($topic) { return response()->json([ 'topic' => new TopicResource($topic), 'articles' => $topic->articles()->with('source')->latest('published_date')->paginate(12) ]); }); } }