Ejemplo n.º 1
0
 public function setTagsAttribute($tags)
 {
     $taggable_id = $this->id;
     $taggable_type = self::class;
     // 기존의 태그가 있으면 지우고
     Taggable::where('taggable_id', $taggable_id)->where('taggable_type', $taggable_type)->delete();
     $tags = explode(',', $tags);
     foreach ($tags as $tagName) {
         $tagName = strtolower(trim($tagName));
         $tag = Tag::firstOrNew(['name' => $tagName]);
         $tag->save();
         $tag_id = $tag->id;
         // 태그를 추가
         Taggable::firstOrNew(['tag_id' => $tag_id, 'taggable_id' => $taggable_id, 'taggable_type' => $taggable_type])->save();
     }
 }
Ejemplo n.º 2
0
 public function get_tagged_list($tag_id)
 {
     $tag = Tag::find($tag_id);
     $qs = $tag->questions()->with('viewCounts')->with('comments.writer')->with('writer.socials')->with('answers.writer')->with('answers.comments.writer')->orderBy('id', 'desc')->paginate(10);
     return view('ncells::qna.pages.list_tagged', ['tag' => $tag, 'qs' => $qs]);
 }