app\models\News::syncTags PHP Method

syncTags() public method

Sync tag relation adding new tags as needed
public syncTags ( array $tags )
$tags array
    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();
    }

Usage Example

 /**
  * Sync tag relation adding new tags as needed
  *
  * @param array $tags
  */
 public function syncTags(array $tags)
 {
     $news = new News();
     $news->syncTags($tags);
 }