Example #1
0
 public static function createByCoordinates($lat, $lng)
 {
     $placeObj = new self();
     $place = $placeObj->firstOrNew(['lat' => $lat, 'lng' => $lng]);
     if ((int) $place->id > 0) {
         return $place;
     }
     /** @var $resp \App\Lib\Api\GooglePlace\Response * */
     $resp = \App\Api\Place::findClosest($lat, $lng);
     $data = $resp->getResult();
     $results = (array) $data->results;
     if (empty($results)) {
         throw new Exception('no results found for lat:' . $lat . ',lng:' . $lng);
     }
     $stdPlace = array_pop($results);
     $place = $placeObj->firstOrNew(['lat' => $stdPlace->geometry->location->lat, 'lng' => $stdPlace->geometry->location->lng]);
     self::bindFromResponse($place, $stdPlace);
     $place->save();
     return $place;
 }
Example #2
0
 public static function add($lat, $lng)
 {
     $userPlaceObj = new self();
     $userPlace = $userPlaceObj->firstOrNew(['lat' => $lat, 'lng' => $lng]);
     if ((int) $userPlace->id != 0) {
         $userPlace->place;
         return $userPlace;
     }
     //add info about userPlace to Places
     $place = \App\Place::createByCoordinates($lat, $lng);
     $userPlace->place()->associate($place);
     $userPlace->save();
     return $userPlace;
 }
Example #3
-1
 public static function add($lat, $lng, $name)
 {
     $centerObj = new self();
     $center = $centerObj->firstOrNew(['requested_lat' => $lat, 'requested_lng' => $lng, 'name' => $name]);
     if ((int) $center->place_id != 0) {
         $center->place->bars;
         return $center;
     }
     //add info about center to Places
     $place = \App\Place::createByCoordinates($lat, $lng);
     $center->place()->associate($place);
     $center->save();
     //add Bars
     $resp = \App\Api\Place::findInRange($lat, $lng);
     $data = $resp->getResult()->results;
     foreach ($data as $responseData) {
         $placeItem = \App\Place::create();
         \App\Place::bindFromResponse($placeItem, $responseData);
         $placeItem->save();
         $placeItem->centres()->attach($place->id);
     }
     return $center;
 }