src/Traits/HasTaxonomies.php
public function addTerm($terms, $taxonomy, $parent = 0, $order = 0)
    {
        $terms = TaxableUtils::makeTermsArray($terms);

        $this->createTaxables($terms, $taxonomy, $parent, $order);

        $terms = Term::whereIn('name', $terms)->pluck('id')->all();

        if (count($terms) > 0) {
            foreach ($terms as $term) {
                if ($this->taxonomies()->where('taxonomy', $taxonomy)->where('term_id', $term)->first())
                    continue;

                $tax = Taxonomy::where('term_id', $term)->first();
                $this->taxonomies()->attach($tax->id);
            }

            return;
        }

        $this->taxonomies()->detach();
    }
public function addTerm($terms, $taxonomy, $parent = 0, $order = 0)
    {
        $terms = TaxableUtils::makeTermsArray($terms);

        $this->createTaxables($terms, $taxonomy, $parent, $order);

        $terms = Term::whereIn('name', $terms)->pluck('id')->all();

        if (count($terms) > 0) {
            foreach ($terms as $term) {
                if ($this->taxonomies()->where('taxonomy', $taxonomy)->where('term_id', $term)->first())
                    continue;

                $tax = Taxonomy::where('term_id', $term)->first();
                $this->taxonomies()->attach($tax->id);
            }

            return;
        }

        $this->taxonomies()->detach();
    }
public function addTerm ( $ terms , $ taxonomy , $ parent = 0 , $ order = 0 ) { $ terms = TaxableUtils :: makeTermsArray ( $ terms ) ; $ this -> createTaxables ( $ terms , $ taxonomy , $ parent , $ order ) ; $ terms = Term :: whereIn ( 'name' , $ terms ) -> pluck ( 'id' ) -> all ( ) ; if ( count ( $ terms ) > 0 ) { foreach ( $ terms as $ term ) { if ( $ this -> taxonomies ( ) -> where ( 'taxonomy' , $ taxonomy ) -> where ( 'term_id' , $ term ) -> first ( ) ) continue ; $ tax = Taxonomy :: where ( 'term_id' , $ term ) -> first ( ) ; $ this -> taxonomies ( ) -> attach ( $ tax -> id ) ; } return ; } $ this -> taxonomies ( ) -> detach ( ) ; }
Add one or multiple terms in a given taxonomy.

@param mixed    $terms
@param string   $taxonomy
@param integer  $parent
@param integer  $order
Add one or multiple terms in a given taxonomy .