/** * @param Tags $tag * @return myModel */ public function getTaggable(Tags $tag, Users $user = null) { $query = Taggables::query()->where('tag_id = :tag:', ['tag' => $tag->id])->andWhere('taggable_type = :type:', ['type' => get_class($this)])->andWhere('taggable_id = :id:', ['id' => $this->id]); if ($user) { $query->andWhere('user_id = :user:'******'user' => $user->id]); } return $query->execute(); }
public function deleteTag(Tags $tag = null) { $query = Taggables::query()->Where('taggable_id = :taggable_id:', ['taggable_id' => $this->id])->andWhere('taggable_type = :type:', ['type' => get_class($this)])->andWhere('user_id = :user:'******'user' => $this->getDI()->get('session')->auth['id']]); if ($tag) { $query = $query->andWhere('tag_id = :tag_id:', ['tag_id' => $tag->id]); } $taggables = $query->execute(); foreach ($taggables as $taggable) { $taggable->delete(); } return $this; }
public function deleteByCurrentUser() { $user = AuthFacade::getService(); $taggables = Taggables::query()->where('tag_id = :tag:', ['tag' => $this->id])->andWhere('user_id = :user:'******'user' => $user->id])->execute(); $taggables->delete(); // dd($taggables); $meta = $this->getTagmetaOrNew(); // dd($meta); $meta->delete(); if ($taggables->count() == 0) { $this->delete(); } }
public function taglogs() { if (null == $this->taglogs) { $this->taglogs = Taggables::query()->leftJoin('Tags', 'Tags.id = Taggables.tag_id')->where('Taggables.user_id = :user:'******'user' => $this->id])->columns(['Taggables.*', 'Taggables.id', 'Taggables.user_id', 'Taggables.tag_id', 'Taggables.created_at', 'Taggables.taggable_type', 'Taggables.taggable_id', 'Tags.name AS tag_name'])->orderBy('Taggables.created_at DESC')->execute(); } return $this->taglogs; }