public static function createFromApi($placeId, $apiData) { $photo = self::create(['place_id' => $placeId, 'photo_reference' => $apiData->photo_reference, 'width' => $apiData->width, 'height' => $apiData->height]); $response = \App\Api\Place::getPhoto($apiData->photo_reference); file_put_contents(\Config::get('place.photo_path') . $photo->id . '.jpg', $response->getResultPhoto()); unset($response); }
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; }
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; }