src/Traits/HasTaxonomies.php
public function scopeWithTerm($query, $term_name, $taxonomy)
    {
        $term_ids = Taxonomy::where('taxonomy', $taxonomy)->pluck('term_id');

        $term     = Term::whereIn('id', $term_ids)->where('name', $term_name)->first();
        $taxonomy = Taxonomy::where('term_id', $term->id)->first();

        return $query->whereHas('taxonomies', function($q) use($term, $taxonomy) {
            $q->where('term_id', $term->id);
        });
    }
public function scopeWithTerm($query, $term_name, $taxonomy)
    {
        $term_ids = Taxonomy::where('taxonomy', $taxonomy)->pluck('term_id');

        $term     = Term::whereIn('id', $term_ids)->where('name', $term_name)->first();
        $taxonomy = Taxonomy::where('term_id', $term->id)->first();

        return $query->whereHas('taxonomies', function($q) use($term, $taxonomy) {
            $q->where('term_id', $term->id);
        });
    }
public function scopeWithTerm ( $ query , $ term_name , $ taxonomy ) { $ term_ids = Taxonomy :: where ( 'taxonomy' , $ taxonomy ) -> pluck ( 'term_id' ) ; $ term = Term :: whereIn ( 'id' , $ term_ids ) -> where ( 'name' , $ term_name ) -> first ( ) ; $ taxonomy = Taxonomy :: where ( 'term_id' , $ term -> id ) -> first ( ) ; return $ query -> whereHas ( 'taxonomies' , function ( $ q ) use ( $ term , $ taxonomy ) { $ q -> where ( 'term_id' , $ term -> id ) ; } ) ; }
Scope by the given term.

@param  object  $query
@param  string  $term_name
@param  string  $taxonomy
@return mixed
Scope by the given term .