public static function updateCountCategory($id) { if (!$id) { return false; } $count = Ad::where('category_id', '=', (int) $id)->count(); $find = self::find($id); $find->count = $count; $find->save(); return true; }
public static function getNearbyAd($ad_id = '', $page = 0) { if (empty($ad_id)) { return false; } $record = self::find($ad_id); if (empty($record)) { return false; } $lat = $record->lat; $lng = $record->lng; $limit = CLF_LIMIT; $skip = $page * $limit; $records = null; if (empty($lat) || empty($lng)) { // Get by country tag } else { // Get by lat long $records = Ad::where('1', '=', '1')->select('*', "((ACOS(SIN({$lat} * PI() / 180) * SIN(lat * PI() / 180) + COS({$lat} * PI() / 180) * COS(lat * PI() / 180) * COS(({$lng} - lng) * PI() / 180)) * 180 / PI()) * 60 * 1.1515 * 1.609344) as distance")->having('distance ', '<=', CLF_DISTANCE)->orderBy('distance', 'ASC')->skip($skip)->take($limit)->get(); } return $records; }