public function getAverageFriends()
 {
     $average = Cache::remember('friends.reports.toolbar', GraphReport::getCacheTime(), function () {
         return DB::select(DB::raw("\n                    SELECT \n                        AVG(numFriends) as avgNum\n                    FROM\n                        (\n                            SELECT \n                                DAYOFWEEK(created_at) AS dow,\n                                DATE(created_at) AS d,\n                                COUNT(*) AS numFriends\n                            FROM users\n                            GROUP BY d\n                        ) AS countFriends\n                    WHERE dow = DAYOFWEEK(NOW())\n                    GROUP BY dow\n                "));
     });
     if (!empty($average)) {
         return $average[0]->avgNum;
     }
     return 0;
 }
 public static function processQuery($query, $timestamp, $limit, $cacheKey, $reset = false)
 {
     $get = Request::all();
     if (empty($get)) {
         $get = ['from' => DatePicker::dateAgo('-1 week'), 'to' => date('Y-m-d')];
     }
     $cacheKey .= $get['from'] . $get['to'];
     if ($reset) {
         Cache::forget($cacheKey);
     }
     return Cache::remember($cacheKey, GraphReport::getCacheTime(), function () use($query, $timestamp, $limit, $get) {
         return $query->where($timestamp, '<=', $get['to'])->where($timestamp, '>=', $get['from'])->take($limit)->get();
     });
 }