private function syncTags(Record $record, array $tags) { $listTags = Tag::lists('id')->toArray(); foreach ($tags as $tag) { if (!in_array($tag, $listTags)) { Tag::create(['name' => $tag]); } } $record->tags()->sync($tags); }