public function statistics() { $thread = Thread::select(DB::raw("count(id) as thread_count, sum(views) as views_count"))->first(); $posts = Post::select(DB::raw("count(id) as posts_count, count(image_url) as image_count"))->first(); return response()->json(['stats' => ['thread_count' => $thread->thread_count, 'views_count' => $thread->views_count, 'posts_count' => $posts->posts_count, 'image_count' => $posts->image_count]]); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Request $request) { $aConv = Conversation::findOrFail($id); $aThread = Thread::select("*")->where("conversation_id", '=', $id)->firstOrFail(); if ($request->has('Content')) { $aConv->update($request->all()); session()->flash('flash_message', 'Conversation updated'); } else { // by definition if the conversation is validated the first thread also is if ($aConv->Pending == 1) { $aConv->Pending = 0; $aThread->Pending = 0; session()->flash('flash_message', 'Conversation is now published'); } else { $aConv->Pending = 1; $aThread->Pending = 1; session()->flash('flash_message', 'Conversation is now unpublished'); } } $aConv->save(); $aThread->save(); return redirect('dashboard'); }