Place details
details() returns a Place, or null when the place is not found:
use RoundlyConsulting\GooglePlaces\DataTransferObjects\DetailsQuery;
use RoundlyConsulting\GooglePlaces\DataTransferObjects\Place;
use RoundlyConsulting\GooglePlaces\Facades\GooglePlaces;
$place = GooglePlaces::details($prediction->placeId); // or new DetailsQuery(...)
if ($place instanceof Place) {
echo $place->name;
echo $place->id;
echo $place->formattedAddress;
echo implode(', ', $place->types);
echo $place->geometry?->location->latitude;
echo $place->geometry?->location->longitude;
foreach ($place->openingHours?->periods ?? [] as $period) {
// from/to are "HHMM" strings; integer accessors are also available.
echo "{$period->day}: {$period->from}–{$period->to}";
echo "{$period->openHour}:{$period->openMinute}";
}
// Photo resource names — pass to photoUrl().
foreach ($place->photos as $photoName) {
$url = GooglePlaces::photoUrl($photoName, maxWidth: 800, maxHeight: 600);
}
$raw = $place->raw; // untouched Google payload
}Per-request field mask and language
Pass a DetailsQuery to override the configured field mask for one request, or to ask for a localised response:
// Override the field mask for this request only:
new DetailsQuery($placeId, fields: ['id', 'displayName', 'location', 'types', 'photos']);
// Localised response:
new DetailsQuery($placeId, language: 'sk');The Place object
| Property | Type | Contents |
|---|---|---|
name | string | Display name. |
id | ?string | Google place id. |
formattedAddress | ?string | Full formatted address. |
types | list<string> | Place types. |
geometry | ?Geometry | location, viewportNorthEast, viewportSouthWest. |
openingHours | ?OpeningHours | isOpen and periods (day, from, to, openHour, openMinute, closeHour, closeMinute). |
photos | list<string> | Photo resource names for photoUrl() / photo(). |
addressComponents | list<AddressComponent> | Filled only when addressComponents is in the field mask. |
raw | array | The untouched Google payload. |
Opening-hour periods expose from and to as “HHMM” strings plus integer openHour, openMinute, closeHour and closeMinute. day follows Google’s convention: 0 is Sunday.
Place helpers
The Place DTO ships convenience accessors:
$place->isOpenNow(); // bool
$place->coordinates(); // ?Location
$place->primaryType(); // ?string
$place->openingHoursFor(1); // list<OpeningHourPeriod> for Monday (0 = Sunday)
$place->components(); // AddressComponents (needs addressComponents in the field mask)primaryType() returns Google’s primaryType when the payload carries it and falls back to the first of the place’s types. The same Place object is returned by text search, nearby search and find place.
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.