示例#1
0
 public function published($input = array())
 {
     $posts = $this->post->published()->latest('created_at');
     if (isset($input['category']) and !empty($input['category'])) {
         $posts = $posts->join('cms_sections', 'cms_sections.id', '=', 'posts.section_id')->where('cms_sections.alias', $input['category']);
     }
     if (isset($input['tag']) and !empty($input['tag'])) {
         $posts = $posts->whereHas('tags', function ($q) use($input) {
             return $q->where('slug', '=', $input['tag']);
         });
     }
     $limit = (isset($input['limit']) and !empty($input['limit'])) ? $input['input'] : Config::get('api.limit');
     $paginated_posts = $posts->paginate((int) $input);
     $posts->select('posts.id as id', 'posts.title as title', 'posts.body as body');
     return $posts->get();
 }
示例#2
0
 public function getFromMultipleSections($input = array(), $section_ids)
 {
     $posts = $this->post->published();
     $posts = $posts->whereHas('section', function ($q) use($section_ids) {
         return $q->whereIn('id', $section_ids);
     });
     $posts = $posts->orderBy('publish_date', 'desc');
     $limit = (isset($input['limit']) and !empty($input['limit'])) ? $input['limit'] : Config::get('api.limit');
     $limit = $this->checkLimit($limit);
     return $posts->paginate($limit);
 }