/** * 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); }
public function createListOfPages() { $this->data['items'] = $this->getElementsWhereHasModel('pages', 'tags', $this->tagId, app('veer')->siteId, array("take_pages" => $this->number_of_items), true)->select('id', 'url', 'title', 'small_txt', 'views', 'created_at', 'users_id')->orderBy('manual_order', 'desc')->get(); $this->data['tagName'] = \Cache::remember('tagNameId' . $this->tagId, 2, function () { return \Veer\Models\Tag::where('id', '=', $this->tagId)->pluck('name'); }); }
public function attach($id, $type = 'page', $toTag = null) { $class = elements($type); $object = $class::find($id); if (!empty($toTag)) { $this->entity = \Veer\Models\Tag::find($id); } if (is_object($object) && is_object($this->entity)) { $object->tags()->attach($this->entity->id); } return $this; }
protected function replaceFilterId($type, $filter_id) { if ($type == "attributes") { $a = \Veer\Models\Attribute::where('id', '=', $filter_id)->select('name', 'val')->first(); if (is_object($a)) { $filter_id = $a->name . ":" . $a->val; } } if ($type == "tags") { $filter_id = \Veer\Models\Tag::where('id', '=', $filter_id)->pluck('name'); } return $filter_id; }
/** * Delete Tag * */ protected function deleteTag($id) { $t = \Veer\Models\Tag::find($id); if (is_object($t)) { $t->pages()->detach(); $t->products()->detach(); $t->delete(); return true; } return false; }
/** * Query Builder: * * - who: 1 Tag * - with: * - to whom: make() | tag/{id} */ public function getTag($id) { return \Veer\Models\Tag::where('id', '=', $id)->first(); }