public function discussion($id)
 {
     $artefact = Artefact::with(['type', 'the_author', 'last_modifier', 'active_instruction'])->find($id);
     $antwoorden = $artefact->children;
     $tags = $artefact->tags;
     $instruction = Instruction::with(['available_types', 'instruction_type', 'the_author'])->where('thread', $artefact->thread)->where('active_from', '<=', date('Y-m-d H:i:s'))->where(function ($q) {
         $q->whereNull('active_until')->orWhere('active_until', '>=', date('Y-m-d H:i:s'));
     })->get();
     $taglist = array();
     foreach ($tags as $tag) {
         $taglist[] = $tag->id;
     }
     $relatedDiscussions = DB::table('artefacts_tags')->whereIn('tag_id', $taglist)->where('artefact_id', '<>', $id)->distinct()->lists('artefact_id');
     $rels = Artefact::whereIn('id', $relatedDiscussions)->get();
     // Aantal antwoorden binnen de thread tellen
     $aantalAntwoorden = DB::table('artefacts')->where('thread', $artefact->thread)->count();
     return response()->json(['artefact' => $artefact, 'answers' => $antwoorden, 'aantalAntwoorden' => $aantalAntwoorden, 'tags' => $tags, 'instruction' => $instruction, 'related' => $rels]);
 }
 public function datavis(Request $request)
 {
     $user = Auth::user();
     //$user = $request->user();
     //dd($request);
     $topics = Artefact::with(['the_author', 'tags', 'last_modifier'])->whereNull('parent_id')->orderBy('created_at', 'desc')->orderBy('last_modified', 'desc')->get();
     $auteurs = DB::table('users')->select('id', 'name')->distinct()->get();
     $tags = Tags::orderBy('tag')->get();
     $aantalAntwoorden = DB::table('artefacts')->select(DB::raw('count(*) as aantal_antwoorden, thread'))->groupBy('thread')->get();
     return view('datavis', ['topic' => $topics, 'user' => $user, 'auteurs' => $auteurs, 'tags' => $tags, 'aantalAntwoorden' => $aantalAntwoorden]);
 }