Validation rules
Validate place ids and coordinates in your own requests:
use RoundlyConsulting\GooglePlaces\Rules\ValidCoordinates;
use RoundlyConsulting\GooglePlaces\Rules\ValidPlaceId;
$request->validate([
'place' => ['required', new ValidPlaceId],
'point' => ['required', new ValidCoordinates], // Location, [lat, lng], or "lat,lng"
]);- ValidPlaceId — a string of 6–512 URL-safe base64 characters (letters, digits, _ and -), e.g. ChIJN1t_tDeuEmsRUsoyG83frY4.
- ValidCoordinates — accepts a Location, a [lat, lng] array, a keyed array (lat/lng or latitude/longitude) or a “lat,lng” string; latitude must be within −90…90 and longitude within −180…180.
Both rules check format only — they never call Google, so they cost nothing.
Messages and translations
The messages come from the package’s google-places::validation translation file, in English and Slovak. They follow the app locale, and :attribute becomes the field’s display name (or your validation.attributes entry), as with Laravel’s own rules:
| Key | Used when | en | sk |
|---|---|---|---|
place_id | ValidPlaceId fails | The :attribute must be a valid Google Place ID. | Pole :attribute musí obsahovať platné Google Place ID. |
coordinates | ValidCoordinates: not a recognisable pair | The :attribute must be a valid latitude/longitude pair. | Pole :attribute musí obsahovať platnú dvojicu zemepisnej šírky a dĺžky. |
latitude | ValidCoordinates: latitude out of range | The :attribute latitude must be between -90 and 90. | Zemepisná šírka v poli :attribute musí byť medzi -90 a 90. |
longitude | ValidCoordinates: longitude out of range | The :attribute longitude must be between -180 and 180. | Zemepisná dĺžka v poli :attribute musí byť medzi -180 a 180. |
To change the wording or add a language, publish the files and edit them in lang/vendor/google-places:
php artisan vendor:publish --tag="google-places-translations"Laravel’s per-request custom messages still work as well. When you call a rule’s validate() directly, your closure receives the message already translated, with :attribute still in it.
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.