public function index($cat_id = 0) { if ($cat_id > 0) { $posts = BlogPost::where('category_id', $cat_id)->get(); } $posts = BlogPost::paginate(20); return view('blog::post.index', compact('posts', 'cat_id')); }
public function show($id = 0) { $post = BlogPost::find($id); $post->cover_wide = asset($post->cover->url('wide')); // get previous post id $previous = BlogPost::where('id', '<', $post->id)->first(); if ($previous) { $previous->cover_thumb = asset($previous->cover->url('thumb')); } // get next post id $next = BlogPost::where('id', '>', $post->id)->first(); if ($next) { $next->cover_thumb = asset($next->cover->url('thumb')); } return response()->json(compact('post', 'next', 'previous'), 200, [], JSON_NUMERIC_CHECK); }