/** * Add an existing term to the inheriting model * * @param $term_id int * The ID of the term to link * * @return object * The TermRelation object */ public function hasTerm($term_id) { $term = $term_id instanceof Term ? $term_id : Term::findOrFail($term_id); $term_relation = ['term_id' => $term->id, 'vocabulary_id' => $term->vocabulary_id]; return $this->related()->where('term_id', $term_id)->count() ? true : false; }
/** * Add an existing term to the inheriting model * * @param $term_id int * The ID of the term to link * * @return object * The TermRelation object */ public function addTerm($term_id) { $term = Term::findOrFail($term_id); $term_relation = ['term_id' => $term->id, 'vocabulary_id' => $term->vocabulary_id]; $this->related()->save(new TermRelation($term_relation)); }