예제 #1
0
 /**
  * Attach Tags
  * 
  */
 protected function attachTags($tags, $object, $separator = ',', $replace = true)
 {
     \Eloquent::unguard();
     $tagArr = [];
     if (is_array($tags)) {
         $matches[1] = $tags;
     } elseif (!empty($separator)) {
         $matches[1] = explode($separator, $tags);
     } else {
         preg_match_all("/^(.*)\$/m", trim($tags), $matches);
     }
     if (!empty($matches[1]) && is_array($matches[1])) {
         foreach ($matches[1] as $tag) {
             $tag = trim($tag);
             if (empty($tag)) {
                 continue;
             }
             $tagDb = \Veer\Models\Tag::firstOrNew(['name' => $tag]);
             if (!$tagDb->exists) {
                 $tagDb->name = $tag;
                 $tagDb->save();
             }
             $tagArr[] = $tagDb->id;
         }
     }
     $this->attachElements($tagArr, $object, 'tags', null, ",", ":", $replace);
 }
예제 #2
0
파일: Tag.php 프로젝트: artemsk/veer-core
 public function add($tag)
 {
     $this->entity = \Veer\Models\Tag::firstOrNew(['name' => $tag]);
     $this->entity->save();
 }