/** * @param $recipeId * @param string $string */ protected function addTags($recipeId, $string = '-') { if ($string != '-' && $string != '') { $tags = explode(',', $string); foreach ($tags as $tag) { try { $tagId = $this->tag->addTag(['tag_name' => trim($tag)]); } catch (QueryException $e) { $tag = $this->tag->getTagFromName(trim($tag)); $tagId = $tag->tag_id; } try { $this->recipeTag->addRecipeTag(['tag_id' => $tagId, 'recipe_id' => $recipeId]); } catch (QueryException $e) { // no process } } } }