Exemplo n.º 1
0
 public function index(Request $request)
 {
     if (!($count = $this->redis->get(COUNTER_KEY))) {
         $count = Votes::count();
         $this->redis->set(COUNTER_KEY, $count);
     }
     if ($count > 999 && $count <= 999999) {
         $kFormat = number_format($count / 1000, 1, '.', ' ') . ' K';
     } elseif ($count > 999999) {
         $kFormat = number_format($count / 1000000, 1, '.', ' ') . ' M';
     } else {
         $kFormat = $count;
     }
     $total = str_pad($count, 6, 0, STR_PAD_LEFT);
     $exist = $request->session()->get('voted');
     $comments = Comments::orderBy('id', 'desc')->limit(5)->get();
     $commentCount = Comments::count();
     return view('home', ['total' => $total, 'count' => $count, 'exist' => $exist, 'kFormat' => $kFormat, 'comments' => $comments, 'commentCount' => $commentCount]);
 }