PHP code example of yieldstudio / nova-google-autocomplete
1. Go to this page and download the library: Download yieldstudio/nova-google-autocomplete library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yieldstudio / nova-google-autocomplete example snippets
use YieldStudio\NovaGoogleAutocomplete\GoogleAutocomplete;
// ....
GoogleAutocomplete::make('Address'),
//You can add a country or countries to autocomplete or leave empty for all.
// Specify a single country
GoogleAutocomplete::make('Address')
->countries('US'),
// Specify multiple countries [array]
GoogleAutocomplete::make('Address')
->countries(['US','AU']),
use YieldStudio\NovaGoogleAutocomplete\AddressMetadata;
use YieldStudio\NovaGoogleAutocomplete\GoogleAutocomplete;
// Now this address field will search and store the address as a string, but also made available the values in the withValues array
GoogleAutocomplete::make('Address')->withValues(['latitude', 'longitude']),
// And you can store the values by autocomplete like this
AddressMetadata::make('lat')->fromValue('latitude'),
AddressMetadata::make('long')->fromValue('longitude'),
// You can disable the field so the user can't edit the metadata
AddressMetadata::make('long')->fromValue('longitude')->disabled(),
// Or you can make the field invisible in the form but collect the data anyways
AddressMetadata::make('long')->fromValue('longitude')->invisible(),
use YieldStudio\NovaGoogleAutocomplete\AddressMetadata;
use YieldStudio\NovaGoogleAutocomplete\GoogleAutocomplete;
// Formatted address will not be stored
GoogleAutocomplete::make('Address')->withValues(['latitude', 'longitude'])->dontStore(),
// This field will be stored
AddressMetadata::make('lat')->fromValue('latitude'),
AddressMetadata::make('long')->fromValue('longitude'),
use YieldStudio\NovaGoogleAutocomplete\AddressMetadata;
use YieldStudio\NovaGoogleAutocomplete\GoogleAutocomplete;
GoogleAutocomplete::make('Address')->withValues(['latitude', 'longitude']),
AddressMetadata::make('coordinates')->fromValue('{{latitude}}, {{longitude}}'),
use YieldStudio\NovaGoogleAutocomplete\GoogleAutocomplete;
GoogleAutocomplete::make('Address')
->withValues([
'route.short_name',
'administrative_area_level_1.long_name',
]),
use YieldStudio\NovaGoogleAutocomplete\AddressMetadata;
use YieldStudio\NovaGoogleAutocomplete\GoogleAutocomplete;
// This autocomplete field will return results that match a business name instead of address.
// All the same address data is still stored.
GoogleAutocomplete::make('Address')->placeType('establishment');
// Autocomplete field
GoogleAutocomplete::make('Location')
->countries('BE')
->withValues(['latitude', 'longitude', 'street_number', 'route', 'locality', 'administrative_area_level_1', 'country', 'postal_code']),
// Field that will capture de response object
AddressMetadata::make('Address')
->fromValuesAsJson()
->invisible()
->onlyOnForms(),
// Display the response object in a Code field
Code::make('Address')->json()->onlyOnDetail(),