Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Google Api Laravel Package

arthem/google-api

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require arthem/google-api
    

    Ensure your composer.json includes the package under require.

  2. Configuration Add your Google API key to .env:

    GOOGLE_API_KEY=your_api_key_here
    

    Publish the config file (if available) or manually define it in config/services.php:

    'google' => [
        'key' => env('GOOGLE_API_KEY'),
    ],
    
  3. First Use Case: Places API Fetch nearby places in Laravel:

    use Arthem\GoogleApi\Places\PlacesService;
    
    $places = app(PlacesService::class)->nearbySearch('40.7128,-74.0060'); // NYC coordinates
    dd($places);
    

Where to Look First

  • Examples: Check the examples/ folder for ready-to-use snippets.
  • Service Classes: Explore Arthem\GoogleApi\Places\PlacesService for Places API methods.
  • Documentation: Refer to Google Places API docs for endpoint specifics.

Implementation Patterns

Workflows

  1. Service Layer Integration Inject the service into a Laravel controller or command:

    public function __construct(private PlacesService $placesService) {}
    
  2. Request Handling Use Laravel’s HTTP client to wrap API calls (if the package supports it):

    $response = Http::withHeaders([
        'Authorization' => 'Bearer ' . config('google.key'),
    ])->get('https://maps.googleapis.com/...');
    
  3. Response Processing Normalize responses with Laravel collections or DTOs:

    $places = collect($placesService->nearbySearch('lat,lng'))
        ->map(fn ($place) => new PlaceResource($place));
    
  4. Caching Responses Cache API responses to reduce calls (e.g., using Laravel’s cache):

    return Cache::remember("places_{$lat}_{$lng}", now()->addHours(1), function () use ($placesService, $lat, $lng) {
        return $placesService->nearbySearch("{$lat},{$lng}");
    });
    

Integration Tips

  • Error Handling: Wrap API calls in try-catch blocks to handle GoogleApiException (if defined) or HTTP errors.
  • Rate Limiting: Implement Laravel’s throttle middleware for API endpoints if needed.
  • Testing: Mock the service in unit tests:
    $this->mock(PlacesService::class)->shouldReceive('nearbySearch')->andReturn([...]);
    

Gotchas and Tips

Pitfalls

  1. API Key Management

    • Hardcoding keys in code violates security best practices. Always use .env.
    • Rotate keys periodically and revoke compromised ones in the Google Cloud Console.
  2. Quota Limits

    • Google APIs enforce usage limits. Monitor your quota in the console.
    • Implement fallback logic for quota-exceeded errors (e.g., retry with exponential backoff).
  3. Deprecation Risks

    • The package has 0 stars/dependents and no active maintenance. Verify compatibility with Google’s API changes manually.
    • Pin the package version in composer.json to avoid breaking updates:
      "arthem/google-api": "1.0.0"
      
  4. Undocumented Features

    • The README mentions "TODOC" for Places API. Assume limited documentation; refer to Google’s official docs for unsupported endpoints.

Debugging

  • Enable Debugging: Use Laravel’s dd() or dump() to inspect raw API responses:
    dd($placesService->nearbySearch('lat,lng')->getRawResponse());
    
  • Logging: Log API calls for auditing:
    Log::debug('Google Places API call', ['params' => $params, 'response' => $response]);
    

Extension Points

  1. Custom Endpoints Extend the package by creating a decorator or proxy:

    class CustomPlacesService extends PlacesService {
        public function customEndpoint($params) {
            return $this->client->get('https://custom-endpoint.com', $params);
        }
    }
    
  2. Middleware Add middleware to the service’s HTTP client for logging/auth:

    $client = Http::withOptions([
        'debug' => true,
    ]);
    
  3. Configuration Overrides Override default config in config/google.php:

    'places' => [
        'base_url' => 'https://custom-mirror.com/places',
    ],
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui