/** * Respond single Article item in JSON. * * @param \App\Article $article * @param \Illuminate\Database\Eloquent\Collection|null $commentsCollection * @param string|null $cacheKey * @return \Illuminate\Http\JsonResponse */ protected function respondItem(Article $article, Collection $commentsCollection = null, $cacheKey = null) { $reqEtag = request()->getETags(); $genEtag = $article->etag($cacheKey); if (config('project.cache') === true and isset($reqEtag[0]) and $reqEtag[0] === $genEtag) { return $this->respondNotModified(); } return json()->setHeaders(['Etag' => $genEtag])->withItem($article, new ArticleTransformer()); }