/** * Return the blog tags */ public function tags() { $tags = Tag::with('posts'); if ($this->property('hideOrphans')) { $tags->has('posts', '>', 0); } return $tags->get(); }
/** * Query and return blog posts * * @return Illuminate\Database\Eloquent\Collection */ public function onRun() { // Start building the tags query $query = Tag::with('posts'); // Hide orphans if ($this->property('hideOrphans')) { $query->has('posts', '>', 0); } // Sort the tags $subQuery = DB::raw('( select count(*) from `bedard_blogtags_post_tag` where `bedard_blogtags_post_tag`.`tag_id` = `bedard_blogtags_tags`.`id` )'); $key = $this->property('orderBy') ?: $subQuery; $query->orderBy($key, $this->property('direction')); // Limit the number of results if ($take = intval($this->property('results'))) { $query->take($take); } $this->tags = $query->get(); }