/** * Returns the url Country analytics data */ public function getCategoryCityAnalytics(Request $request, $category) { $rangeTo = Input::get('t'); $rangeFrom = Input::get('f'); // No use Unit here $unit = Input::get('u'); if (!strcmp($category, 'all')) { $cityData = Url::join('hits', 'urls.id', '=', 'hits.url_id')->whereBetween('hits.created_at', array($rangeFrom, $rangeTo))->select(\DB::raw('count(*) as count, city, country'))->groupBy('city')->get(); } else { $cityData = Url::join('hits', 'urls.id', '=', 'hits.url_id')->where('category', $category)->whereBetween('hits.created_at', array($rangeFrom, $rangeTo))->select(\DB::raw('count(*) as count, city, country'))->groupBy('city')->get(); } // Build response object $res = new \stdClass(); $res->status = "Success"; $res->data = $cityData; return response()->json($res, 200); }