Download the PHP package tapp/filament-google-autocomplete-field without Composer
On this page you can find all versions of the php package tapp/filament-google-autocomplete-field. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tapp/filament-google-autocomplete-field
More information about tapp/filament-google-autocomplete-field
Files in tapp/filament-google-autocomplete-field
Package filament-google-autocomplete-field
Short Description Filament plugin that provides a Google Autocomplete field
License MIT
Homepage https://github.com/tapp/filament-google-autocomplete-field
Informations about the package filament-google-autocomplete-field
Filament Google Autcomplete Field
This plugin provides an address autocomplete using Google Place autocomplete API, with fully customizable address fields.
[!NOTE] The Google Places API package is used to make API requests to Google Places.
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
Optionally, you can publish the translation files with:
Setup
On Google console, create an application and enable the Places API.
- Click on "ENABLE APIS AND SERVICES"
- Search for "Places api"
- Click to enable it
- Get the API key
In your Laravel application, add the Google API key to GOOGLE_PLACES_API_KEY
in your .env
file:
Appareance
Usage
Add the GoogleAutocomplete
field to your form:
This will use the default address fields and Google API options. You can also customize the address fields and Google Place API options. See all the options available on Available options
item below. For example:
Available Options
Autocompleted Fields
You can use the withFields
method to define the fields that will be autocompleted.
By default the following fields are set if this method isn't provided:
You can override these default fields by passing an array of Filament form fields to withFields
method:
Combining Fields
You can combine multiple fields returned by Google API in one field using curly braces {}
to wrap the fields in 'data-google-field'
extra input attribute. For example, the address
field below will contain the street_number
, route
, and sublocality_level_1
and the coordinates
field will contain the latitude
and longitude
fields:
Field Name
If your database field have a different name than the Google field (for example you DB field is zip
and you want to use the Google's postal_code
value returned by API), you can tie the API field to the DB field by passing your DB field name to 'data-google-field'
on extraInputAttributes
method like so:
These are the names of the Google metadata fields available to use:
long_name and short_name
Google's Places API returns long_name
and short_name
values for address fields. You can choose which one to display by passing it to the 'data-google-value'
on extraInputAttributes
method:
E.g. of long_name
and short_name
data returned by Google's API:
Autocomplete Field Column Span
The default column span for autcomplete select field is 'full'
. You can define other value (same as supported by Filament's columnSpan()
) using the autocompleteFieldColumnSpan
method:
Autocomplete Field Search Debounce
The default search debounce is 2 seconds to avoid too many requests to Google Places API. You can define other value using autocompleteSearchDebounce
method:
These following Google API options can be passed to the GoogleAutocomplete
field:
Countries
Add the countries
method to restrict the countries that should be used for autocomplete search.
The countries must be passed as a two character ISO 3166-1 Alpha-2 compatible country code. You can find the country codes available at Wikipedia: List of ISO 3166 country codes.
Language
The language which results should be returned. These are the supported language codes.
Location
The point around which to retrieve place information as latitude,longitude
.
Please refer to the Google documentation to a detailed description of this option.
LocationBias
Prefer results in a specified area, by specifying either a radius plus lat/lng, or two lat/lng pairs representing the points of a rectangle. If this parameter is not specified, the API uses IP address biasing by default.
Please refer to the Google documentation to a detailed description of this option.
LocationRestriction
Restrict results to a specified area, by specifying either a radius plus lat/lng, or two lat/lng pairs representing the points of a rectangle.
Please refer to the Google documentation to a detailed description of this option.
Offset
The position, in the input term, of the last character that the service uses to match predictions. For example, if the input is Google and the offset is 3, the service will match on Goo.
Origin
The origin point as latitude,longitude
from which to calculate straight-line distance to the destination specified.
Please refer to the Google documentation to a detailed description of this option.
Radius
The distance in meters within which to return place results.
Please refer to the Google documentation to a detailed description of this option.
Region
The region code, specified as a country code top-level domain (ccTLD) two-character value.
SessionToken
Random string which identifies an autocomplete session for billing purposes.
Please refer to the Google documentation to a detailed description of this option.
PlaceTypes
Restrict the results to be of a certain type. Pass the available types as an array:
Please refer to the Google documentation to a detailed description of this option.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Tapp Network
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of filament-google-autocomplete-field with dependencies
spatie/laravel-package-tools Version ^1.16
filament/filament Version ^3.0-stable
illuminate/contracts Version ^10.0||^11.0
skagarwal/google-places-api Version ^2.2