public function show(\App\Article $article) { $article->increment('view_count', 1); if ($article->id == DB::table('articles')->first()->id) { $previous = $article->photo; } else { $previous = \App\Article::where('id', '<', $article->id)->orderBy('id', 'desc')->firstOrFail()->photo; } if ($article->id == DB::table('articles')->orderBy('id', 'desc')->first()->id) { $next = $article->photo; } else { $next = \App\Article::where('id', '>', $article->id)->orderBy('id', 'asc')->firstOrFail()->photo; } return view('articles.show', compact('article', 'previous', 'next')); }
public function show(Article $article) { $comments = $article->comments()->with('user')->recent()->simplePaginate(10); $article->increment('view_count'); return view('articles.show', compact('article', 'comments')); }