Places carry photo resource names in $place->photos. photoUrl() builds the media URL for one of them:
use RoundlyConsulting\GooglePlaces\Facades\GooglePlaces;
// $photoName is a photo resource name from a place ($place->photos).
$url = GooglePlaces::photoUrl($photoName, maxWidth: 800, maxHeight: 600);photoUrl() embeds your API key as the key query parameter, so keep that URL server-side. For anything that reaches a browser, use photo().
Fetching photo bytes
photo() returns a handle on one place photo. The API key is sent as a request header and never exposed to the browser — url() returns Google’s key-free media URL:
use RoundlyConsulting\GooglePlaces\Facades\GooglePlaces;
// $photoName is a photo resource name from a place ($place->photos).
$photo = GooglePlaces::photo($photoName, maxWidth: 800, maxHeight: 600);
$url = $photo->url(); // Google's key-free media URL (safe for the browser)
$bytes = $photo->contents(); // raw image bytes
$path = $photo->save('public', 'p.jpg'); // store on a filesystem disk → returns the path
// The same two requests without the handle:
GooglePlaces::photoUri($photoName, 800, 600);
GooglePlaces::photoContents($photoName, 800, 600);- url() — runs photoUri(): Google’s final media URL without your key, safe to put in an <img> tag.
- contents() — runs photoContents(): the raw image bytes.
- save($disk, $path) — writes the bytes to any Laravel filesystem disk and returns the path.
- Width and height default to 1600 px; a failed fetch or a missing key throws a PlacesException.
Every photo request goes through the client like any other call: configured timeouts and connection retries, paced on the places rate-limit budget, reported through the lifecycle events and intercepted by GooglePlaces::fake(). Photos are never cached — store the ones you reuse:
// Cache a place's hero image locally once:
$path = "places/{$place->id}.jpg";
if (! Storage::disk('public')->exists($path) && $place->photos !== []) {
GooglePlaces::photo($place->photos[0], 1200, 800)->save('public', $path);
}Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.