/** * @name getFetchAll * * Fetches either all posts or all posts of given type * Specific controllers for different types of post should use this function * for retriving posts of their type * In specific case where you want to return all posts, use 'all' as post type * * @param string $type [optional] - Type of the post to be returned, defaults to $postType * @return Response - returns Respons in json format including array of posts or error * * @todo extend this function so it can accept some filters like order or limit... */ public function getFetchAll($type = false) { $query = Post::query(); if (empty($type)) { $type = $this->postType; } if ($type !== 'all') { $query->where('type', '=', $type); } $query->with(array("post_contents", "featured_image.file")); // @CHANGE $status = array('publish', 'draft'); $query->whereIn('status', $status); // @CHANGE $order_by = 'created_at'; $order = 'desc'; $query->orderBy($order_by, $order); $result = $query->get(); return Response::json($result); }
/** * @name getArticles * * * @param mixed $status [optional] - article status * @return Response - returns Respons in json format including array of posts or error * * @todo move this code to article repository */ public function getArticles($status = array()) { $query = Post::query(); // @CHANGE $query->where('type', '=', $this->postType); // status // ------------------------------------- $status = array('publish', 'draft'); $query->whereIn('status', $status); // relations // ------------------------------------- $query->with(array("post_contents", "featured_image.file")); // order // ------------------------------------- $order_by = 'created_at'; $order = 'desc'; $query->orderBy($order_by, $order); // get // ------------------------------------- $result = $query->get(); return Response::json($result); }