skagarwal/google-places-api
PHP wrapper for Google Places API Web Service with Laravel support. Includes Places API and Places API (New) endpoints like autocomplete/search, built on Saloon in v3. Composer install, fluent client setup, configurable SSL and error handling.
Pros:
fields=['name', 'rating']) to optimize payload size and reduce API costs.Response objects, compatible with Laravel’s collect(), json(), or raw arrays, and supports custom headers/SSL settings.Cons:
Cache facade) for frequent or expensive queries.GooglePlaces to the container in AppServiceProvider).GooglePlaces::dispatch()->nearbySearch(...)).spatie/laravel-geocoder for hybrid geocoding workflows.MockClient or Laravel’s HTTP tests.nearbySearch(lat,lng,radius) vs. nearbySearch('lat,lng')). Use a feature flag or adapter pattern to phase out v2.fields=['*']) increase response size. Optimize with minimal fields..env (not config) and restricted via Google Cloud IAM.verifySSL: false).config('services.google.key') + environment variables.)Reportable exceptions or be logged silently?Cache::remember() or Redis with TTLs (e.g., 1 hour for autocomplete).Log::channel('google') or a dedicated queue worker.)php artisan vendor:publish --provider="SKAgarwal\GoogleApi\ServiceProvider") and bind the client to the container:
$this->app->singleton(GooglePlaces::class, function ($app) {
return GooglePlaces::make(config('services.google.key'));
});
config/google.php:
'key' => env('GOOGLE_PLACES_API_KEY'),
'verify_ssl' => env('APP_ENV') !== 'local',
'headers' => [
'Accept' => 'application/json',
],
GooglePlaces::connection('google')->withHeaders(['X-Custom-Header' => 'value']);
GooglePlaces::macro('searchRestaurants', function ($lat, $lng) {
return $this->nearbySearch($lat, $lng, 500, ['type' => 'restaurant']);
});
if (config('features.use_google_places_v3')) {
return GooglePlaces::make()->autocomplete($query);
}
return GooglePlacesLegacy::make()->placeAutocomplete($query);
@deprecated PHPDoc).public function test_nearby_search_returns_expected_fields() {
$response = GooglePlaces::make()->nearbySearch(40.748817, -73.985428, 500);
$response->assertSuccessful();
$response->assertHasField('results.0.name');
}
laravel-shift/laravel-13-compatibility if needed.placeDetails).composer.json to avoid breaking changes:
"skagarwal/google-places-api": "^3.2"
env() + config() to switch keys without code changes.google-places:rotate-key Artisan command to update the config file.GOOGLE_PLACES_API.md in /docs with:
GooglePlacesException class:
class GooglePlacesException extends \Exception {
public static function fromResponse(SaloonResponse $response) {
return new self($response->body()['error_message'] ?? 'Unknown
How can I help you explore Laravel packages today?