public function syncTags(array $tags) { Tag::addNeededTags($tags); if (count($tags)) { $this->tags()->sync(Tag::where('user_id', Auth::user()->id)->whereIn('title', $tags)->lists('id')->all()); return; } $this->tags()->detach(); }
/** * Sync tag relation adding new tags as needed * * @param array $tags */ public function syncTags(array $tags) { Tag::addNeededTags($tags); if (count($tags)) { $this->tags()->sync(Tag::whereIn('tag', $tags)->lists('id')->all()); return; } $this->tags()->detach(); }
/** * Sync tag relation adding new tags as needed * @param array $tags */ public function syncTags(array $tags) { Tag::addNeededTags($tags); if (count($tags)) { // After method sync() is complete, only the IDs in the array $tags will exist // in the intermediate table:post_tag_pivot $this->tags()->sync(Tag::whereIn('tag', $tags)->pluck('id')->all()); return; } $this->tags()->detach(); }