- How do I install the TomTom provider for Geocoder in a Laravel project?
- Run `composer require geocoder-php/tomtom-provider` to install the package. Then register the provider in your Laravel Service Provider by binding it to the Geocoder container singleton, using your TomTom API key from `.env`. Example: `$geocoder->registerProvider(new TomTomProvider(env('TOMTOM_API_KEY')))`.
- What Laravel versions does this package support?
- The package supports Laravel 5.5+ and PHP 7.4+. Verify compatibility by checking the `composer.json` constraints in the package repository. If using Laravel 10+, ensure no breaking changes exist with the Geocoder library’s latest version.
- Can I use this provider for reverse geocoding (coordinates to addresses)?
- Yes, the TomTom provider supports both forward (address to coordinates) and reverse geocoding. Use `$geocoder->reverse($latitude, $longitude)` to convert coordinates to addresses, returning standardized Geocoder results.
- How do I handle TomTom API rate limits in production?
- TomTom’s free tier has strict limits (e.g., 25,000 requests/month). Implement caching (e.g., Redis) with a TTL of 1–24 hours for static data, and use Laravel Queues to batch or delay non-critical geocoding requests. Monitor API responses for HTTP 429 errors.
- Is there a fallback mechanism if TomTom’s API fails?
- The package doesn’t include built-in fallback logic, but you can manually register multiple providers (e.g., TomTom + OpenStreetMap) and handle failures via try-catch blocks. Alternatively, extend the Geocoder instance to implement a priority chain for providers.
- How do I configure the TomTom provider in Laravel’s `.env` file?
- Add your TomTom API key to `.env` as `TOMTOM_API_KEY=your_key_here`. The provider also supports customizing the API host (e.g., `TOMTOM_HOST=api.tomtom.com`). Configure these values in your Service Provider or directly in the provider initialization.
- Can I mock the TomTom provider for unit testing in Laravel?
- Yes, use Laravel’s Mockery or Vesper to mock the `TomTomProvider` class. Override its `geocode()` or `reverse()` methods in your tests to return mock responses. Example: `$mockProvider->shouldReceive('geocode')->andReturn($mockResult)`.
- What are the alternatives to this package for Laravel geocoding?
- Alternatives include `geocoder-php/mapbox-provider` (Mapbox API), `geocoder-php/google-maps-provider` (Google Maps), or `geocoder-php/openstreetmap-provider` (free, open-source). Compare pricing, accuracy, and rate limits before choosing.
- How do I store geocoded results in a Laravel database?
- Use Eloquent models to store geocoded data (e.g., `latitude`, `longitude`, `formatted_address`). For searchability, add a `scout` trait or use Laravel Scout with Algolia. Cache frequent queries in Redis to reduce API calls.
- Is this package actively maintained? How can I check?
- Check the GitHub repository for recent commits (last 6–12 months) and open issues. The package has low stars, so verify compatibility with the latest Geocoder library and TomTom API changes. Monitor for updates or consider forking if maintenance is critical.