Example #1
0
 /**
  * gets the hood_id from location string. creates table records if not exists
  *
  * @return hood object
  * @author gcg
  */
 public static function fromLocation($location)
 {
     $hood = false;
     $location_parts = explode(",", $location);
     foreach ($location_parts as $index => $lp) {
         $location_parts[$index] = trim($lp);
     }
     try {
         $city = City::firstOrCreate(['name' => $location_parts[2]]);
     } catch (Exception $e) {
         Log::error('HoodModel/city', (array) $e);
         return false;
     }
     try {
         $district = District::firstOrCreate(['name' => $location_parts[1], 'city_id' => $city->id]);
     } catch (Exception $e) {
         Log::error('HoodModel/district', (array) $e);
         return false;
     }
     try {
         $hood = Hood::firstOrCreate(['name' => $location_parts[0], 'city_id' => $city->id, 'district_id' => $district->id]);
     } catch (Exception $e) {
         Log::error('HoodModel/hood', (array) $e);
         return false;
     }
     return $hood;
 }
Example #2
0
 /**
  * get a list of cities
  *
  * @return json
  * @author
  **/
 public function getCities($q = null)
 {
     $cities = City::orderBy('name', 'asc');
     if ($q !== null and $q !== 'null') {
         $cities->where('name', 'LIKE', '%' . $q . '%');
     }
     $cities = $cities->get();
     if (null === $cities) {
         $cities = [];
     } else {
         $cities = $cities->toArray();
     }
     return response()->api(200, 'Cities: ', $cities);
 }