spatie/statamic-algolia-places
Add an Algolia Places-powered location fieldtype to Statamic 3. Provides address autocomplete in the control panel and stores structured location data (city, country, lat/lng, postcode, etc.). Supports all Algolia Places configuration options.
Installation
composer require spatie/statamic-algolia-places
Publish the fieldtype assets (if needed):
php artisan vendor:publish --provider="Spatie\AlgoliaPlaces\AlgoliaPlacesServiceProvider"
Register the Fieldtype Add the fieldtype to your Statamic blueprint:
fields:
location:
type: algolia_places
algolia_app_id: 'YOUR_APP_ID'
algolia_search_key: 'YOUR_SEARCH_KEY'
First Use Case
Create a content entry with the fieldtype. The dropdown will autocomplete locations via Algolia Places API. The saved data will include structured location details (e.g., name, city, country).
Content Creation
fields:
venue:
type: algolia_places
algolia_app_id: '{{ env("ALGOLIA_APP_ID") }}'
algolia_search_key: '{{ env("ALGOLIA_SEARCH_KEY") }}'
instructions: "Select the venue from the autocomplete dropdown."
Data Retrieval Access the structured location data in templates:
{{ entry.venue.name }} {# e.g., "Kruikstraat 22" #}
{{ entry.venue.city }}, {{ entry.venue.country }} {# e.g., "Antwerpen, België" #}
Validation Ensure required fields are set in the blueprint:
fields:
address:
type: algolia_places
required: true
Environment Variables
Store ALGOLIA_APP_ID and ALGOLIA_SEARCH_KEY in .env for security:
ALGOLIA_APP_ID=your_app_id
ALGOLIA_SEARCH_KEY=your_search_key
Reference them in blueprints:
algolia_app_id: '{{ env("ALGOLIA_APP_ID") }}'
Custom Styling Override the fieldtype’s CSS/JS by publishing assets and extending:
php artisan vendor:publish --tag=algolia-places-assets --provider="Spatie\AlgoliaPlaces\AlgoliaPlacesServiceProvider"
Modify the published files in resources/js or resources/css.
Fallback for Offline Add a default value or instructions for when Algolia is unavailable:
fields:
location:
type: algolia_places
default: { name: "Default Location", city: "City", country: "Country" }
Algolia API Limits
cache() helper).Fieldtype Not Rendering
algolia_app_id or algolia_search_key in the blueprint..env.Data Structure Mismatch
{{ entry.location.city ?? 'N/A' }}
Archived Package
Console Errors Check browser console for Algolia API errors (e.g., invalid keys, CORS issues). Validate keys in the Algolia Dashboard.
Network Requests
Use browser dev tools to inspect the Algolia Places API calls. Ensure the search endpoint is reachable:
https://places-algolia.deta.dev/1/places/query?...
Customize Autocomplete Options
Pass additional Algolia Places parameters via the attributes key in the blueprint:
fields:
location:
type: algolia_places
attributes:
language: 'en'
aroundLatLngViaIP: true
See Algolia Places API docs for options.
Post-Save Processing
Use Statamic’s entry.saving event to transform the location data:
// In a service provider or listener
Event::listen(EntrySaving::class, function (EntrySaving $event) {
$location = $event->entry->location;
$event->entry->setData('formatted_address', "{$location['name']}, {$location['city']}");
});
Fallback to Manual Input
Combine with a text fieldtype for manual overrides:
fields:
location:
type: algolia_places
manual_location:
type: text
hidden: true {# Show only if Algolia fails #}
How can I help you explore Laravel packages today?