public function existsByTitle($title, $taxonomyId = null) { if ($taxonomyId) { $term = Term::where('title', 'like', $title)->first(); } else { $term = Term::where('title', 'like', $title)->where('taxonomy_id', $taxonomyId)->first(); } if ($term) { return $term->id; } }