/**
  * Save microblog's tags
  *
  * @param int $microblogId
  * @param array $tags
  */
 public function setTags($microblogId, array $tags)
 {
     Microblog\Tag::where('microblog_id', $microblogId)->delete();
     foreach ($tags as $name) {
         $tag = Tag::firstOrCreate(['name' => $name]);
         Microblog\Tag::create(['microblog_id' => $microblogId, 'tag_id' => $tag->id]);
     }
 }
Example #2
0
 /**
  * @param $model
  * @param RepositoryInterface $repository
  * @return mixed
  */
 public function apply($model, Repository $repository)
 {
     $subSql = Tag::select(['microblog_id'])->whereRaw('name = \'' . $this->tag . '\'');
     $query = $model->whereRaw('microblogs.id IN(' . $subSql->toSql() . ')');
     return $query;
 }