/** * Where has posts based on args * * @return \Illuminate\Database\Eloquent\Builder */ public function queryHasPosts($query, $args = array()) { $query->join('term_relationships as tr', 'tr.term_taxonomy_id', '=', 'tt.term_taxonomy_id'); $post_ids = Post::query()->select('ID')->where($args)->get()->map(function ($post) { return $post['ID']; })->toArray(); $query->whereIn('tr.object_id', $post_ids); $query->groupBy('terms.term_id'); return $query; }
/** * Create a new Eloquent model instance. * * @param array $attributes * @return void */ public function __construct(array $attributes = []) { parent::__construct($attributes); $this->buildAppends(); }