Beispiel #1
0
 public function popularThreads($page, $board)
 {
     $count = Thread::count();
     $threads = Thread::orderBy(DB::raw("((30 - (DATEDIFF(NOW(), created_at))) / 30 * views)"), "DESC")->take(15);
     if ($board != 'all') {
         $threads->where('board', '=', $board);
     }
     $result = [];
     foreach ($threads->get() as $thread) {
         $threadArray = $thread->toArray();
         $threadArray['post'] = $thread->posts()->take(1)->get()->toArray();
         $result[] = $threadArray;
     }
     return response()->json(['total_rows' => $count, 'threads' => $result]);
 }