public function googleMaps(Location $location) { if ((empty($location->google_maps_base64) || empty($location->google_maps_type)) && !empty($location->latitude) && !empty($location->longitude)) { $image_path = 'https://maps.googleapis.com/maps/api/staticmap?'; $image_path .= 'center=' . $location->latitude . ',' . $location->longitude; $image_path .= '&zoom=16'; $image_path .= '&size=300x300'; $image_path .= '&maptype=roadmap'; $image_path .= '&markers=color:red%7Clabel:' . $location->id . '%7C' . $location->latitude . ',' . $location->longitude; $image_path .= '&language=iw'; $image_path .= '&key=AIzaSyCcIcPu2LwdIgraVp4WrXhjGanyySaj72A'; $image = file_get_contents($image_path); $type = getimagesize($image_path)['mime']; $base64 = base64_encode($image); $location->update(['google_maps_base64' => $base64, 'google_maps_type' => $type]); } }