public function answers($id, $author = null, $tag = null, $keyword = null)
 {
     $parent = Artefact::all()->find($id);
     $parent = BmoocJsonController::search($parent, $author, $tag, $keyword);
     $tree = $parent;
     $parent->children = BmoocJsonController::buildTree($parent->children, $parent->id, $author, $tag, $keyword);
     return response()->json($tree);
 }
 public function tree(Request $request)
 {
     // LIST OF TOPICS
     $topics = DB::table('artefacts')->orderBy('updated_at', 'desc')->whereNull('parent_id')->get();
     $topic = Input::get('topic');
     if ($topic == "all") {
         $topic = null;
     } else {
         if (!is_numeric($topic)) {
             $topic = $topics[0]->thread;
         }
     }
     // BUILD TREE
     $parent = DB::table('artefacts')->select('id')->where('thread', 'LIKE', $topic)->where('parent_id', '=', NULL)->get();
     $parent = Artefact::all()->find($parent[0]->id);
     $tree = $parent;
     $parent->children = BmoocJsonController::buildTree($parent->children, $parent->id);
     // GET PLAIN LIST
     $list = DB::table('artefacts')->where('thread', 'LIKE', $topic)->get();
     $tags = DB::table('artefacts_tags')->select('artefact_id', 'tag_id')->leftJoin('artefacts', 'artefact_id', '=', 'artefacts.id')->where('thread', 'LIKE', $topic)->get();
     $user = Auth::user();
     if ($user && $user->role == "editor") {
         return view('admin.data.tree', ['topics' => $topics, 'topic' => $topic, 'tree' => $tree, 'list' => $list, 'tags' => $tags]);
     } else {
         App::abort(401, 'Not authenticated');
     }
 }