public function show($postID) { $post = Cache::remember('post_' . $postID, 15, function () use($postID) { return Post::with('tags')->find($postID); }); return self::makeResponse($post); }
public function showPost($slug, Request $request) { $post = Post::with('tags')->whereSlug($slug)->firstOrFail(); $tag = $request->get('tag'); if ($tag) { $tag = Tag::whereTag($tag)->firstOrFail(); } return view($post->layout, compact('post', 'tag')); }
public static function getList($count = 10) { try { return Post::with('user')->orderBy('public_date', 'DESC')->paginate($count); } catch (Exception $e) { Log::info('Post:getList(): ' . $e->getMessage()); return array(); } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $post = Post::with(array('User' => function ($query) { $query->select('id', 'name'); }))->find($id); if (!$post) { return Response::json(['error' => ['message' => 'Post does not exist']], 404); } // get previous joke id $previous = Post::where('id', '<', $post->id)->max('id'); // get next joke id $next = Post::where('id', '>', $post->id)->min('id'); return Response::json(['previous_joke_id' => $previous, 'next_joke_id' => $next, 'data' => $this->transform($post)], 200); }
/** * Display a listing of the resource. * * @return Response */ public function index() { return $this->getResponse(Post::with(['author', 'comments', 'author.posts'])->get()->all()); }
/** * Return data for normal index page * * @return array */ protected function normalIndexData() { $posts = Post::with('tags')->where('published_at', '<=', Carbon::now())->where('is_draft', 0)->orderBy('published_at', 'desc')->simplePaginate(config('upload.posts_per_page')); return ['title' => config('upload.title'), 'subtitle' => config('upload.subtitle'), 'posts' => $posts, 'page_image' => config('upload.page_image'), 'meta_description' => config('upload.description'), 'reverse_direction' => false, 'tag' => null]; }
public function index() { $posts = Post::with('categories')->get(); return $this->postTransformer->transformCollection($posts); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $model = Post::with('tags')->get()->toArray(); return response()->json(['error' => false, 'data' => ['posts' => $model, 'counts' => count($model)]], 200); }