public function taxonomy($taxonomy, $term) { return $this->whereHas('taxonomies', function ($query) use($taxonomy, $term) { $query->where('taxonomy', $taxonomy)->whereHas('term', function ($query) use($term) { $query->where('slug', $term); }); }); }