Skip to content

Headless Usage ​

Last updated: 2026-11-24

Using Filament Address Pro without the admin panel: your own Blade, Livewire, Inertia or mobile form on top of the package's country data, geocoding and verification. The address logic lives in services, so a custom form gets the same subdivision matching, verification, error codes and review reasons as the Filament form.

The admin panel is still useful next to a custom form: staff review flagged addresses there (see Reviewing flagged addresses).

Table of Contents ​


Choosing an approach ​

Your front endUsePaid API calls
Blade, Livewire, controllers, jobs, commandsThe PHP services: AddressResolver, CountryService, SubdivisionMatcherWhen you call a resolver
Inertia (React, Vue, Svelte), an SPA, a mobile appThe opt-in HTTP API; a worked example: React formWhen the form calls resolve/* or verify
Any form, without address lookups in the formSave the Address and let silent verification verify itOne verification per save
A Filament form outside the admin panelAddressForm::schema() in a minimal panel; see Public FormsAs in the admin panel

Official front-end components are planned: a standalone Livewire address form in 1.2, then React (1.3) and Vue (1.4) components. Until then, the services and the HTTP API are the supported way to build your own.

From PHP ​

Each address flow is one call to AddressResolver, which returns a ResolvedAddress: either a complete record whose keys are Address columns, or a coded error. The API Reference describes each method; this is how they fit a form.

Form eventCall
User leaves line 1 after typing or pasting an addressBlurGeocodingPolicy::shouldGeocode(), then resolveTyped()
User picks a Places Autocomplete suggestionresolvePlace()
User clicks Verifyverify()
User picks a point (coordinates)resolveCoordinates()
User changes the citylocate() (new coordinates only, no verification)
Country or subdivision dropdownsCountryService::getCountryAddressDefinition(), getAdministrativeAreaOptions(), getLocalityOptions(), getDependentLocalityOptions()
Geocoder or user text that must match subdivision IDsSubdivisionMatcher::match()

In a controller ​

php
use Illuminate\Http\Request;
use Viewflex\FilamentAddress\Services\AddressResolver;

public function store(Request $request, AddressResolver $resolver)
{
    $data = $request->validate([
        'address_line_1' => ['required', 'string', 'max:255'],
        'address_line_2' => ['nullable', 'string', 'max:255'],
        'locality' => ['nullable', 'string', 'max:255'],
        'administrative_area' => ['nullable', 'string', 'max:255'],
        'postal_code' => ['nullable', 'string', 'max:20'],
        'country_code' => ['required', 'string', 'size:2'],
    ]);

    $resolved = $resolver->verify($data);

    if (! $resolved->isSuccess()) {
        // Nothing resolved: incomplete address, provider outage, ... ($resolved->error()->code)
        return back()->withErrors(['address_line_1' => $resolved->error()->message])->withInput();
    }

    // Verified, standardized and matched to subdivision IDs; flagged needs_review when the
    // provider rejected it ($resolved->verificationError()) or found a problem ($resolved->reviewStatus())
    $request->user()->addresses()->create($resolved->fields());

    return redirect()->route('account.addresses');
}

This saves the standardized version without asking. To let the user choose, as the Filament form does, check $resolved->requiresChoice() and show $resolved->original() next to $resolved->comparedFields() before saving.

addresses() comes from the HasAddresses trait.

In a Livewire component ​

php
use Livewire\Component;
use Viewflex\FilamentAddress\Services\AddressResolver;
use Viewflex\FilamentAddress\Services\Geocoding\BlurGeocodingPolicy;

class AddressStep extends Component
{
    public array $address = ['country_code' => 'US', 'address_line_1' => ''];

    public ?array $suggestion = null;   // ResolvedAddress::toArray() when the user must choose

    // wire:model.blur="address.address_line_1"
    public function updatedAddress(mixed $value, string $key): void
    {
        if ($key !== 'address_line_1' || ! app(BlurGeocodingPolicy::class)->shouldGeocode((string) $value, $this->address)) {
            return;
        }

        $resolved = app(AddressResolver::class)->resolveTyped($this->address);

        if (! $resolved->isSuccess()) {
            return;   // zero_results and incomplete_query: let the user keep typing
        }

        if ($resolved->requiresChoice()) {
            $this->suggestion = $resolved->toArray();

            return;
        }

        $this->address = $resolved->fields();
    }
}

BlurGeocodingPolicy applies the addresses.blur_geocoding settings (minimum length, paste detection, completeness), so a custom form spends API calls as sparingly as the Filament form.

From JavaScript ​

Enable the HTTP API and call the same flows as JSON endpoints: resolve/input for resolveTyped(), resolve/place, resolve/coordinates, resolve/locate and verify, plus the country, subdivision, postal code and format endpoints for the form itself. Each resolve and verify response is ResolvedAddress::toArray(), with HTTP status 200 even when nothing was found: check success.

The React (Inertia) example is a complete form on these endpoints: country select, cascading subdivision dropdowns, blur resolve, the choice between the user's version and the standardized one, and saving.

BlurGeocodingPolicy isn't exposed over HTTP. Use a simple check before calling resolve/input (the example sends line 1 once it has 5 characters and a digit). resolveTyped() checks completeness before calling Google and returns incomplete_query without a paid call.

Saving the address ​

The keys of ResolvedAddress::fields() (and of fields in the JSON) are Address columns, so the record goes straight into create() or fill():

php
$entity->addresses()->create($resolved->fields() + ['label' => 'Shipping']);
  • Text and IDs together. Store both the subdivision text (locality) and its ID (locality_id). When the user picks from a dropdown, store the option's name and id; when you store text yourself, run it through SubdivisionMatcher. An unmatched level keeps its text with a null ID.
  • Edits after a resolve. A record resolved from the user's input describes that input. If the user edits an address field afterwards, clear is_verified, verification_provider, verified_at and verification_metadata before saving (or resolve again). The Filament form also flags the record needs_review with the edited_after_verification reason.
  • Keeping the user's version. When the user rejects the standardized address, save their values unverified and flagged: is_verified false, needs_review true, and verification_metadata {"review_reasons": [{"code": "suggested_changes", "detail": {"fields": [...]}}]} with the names from changes. Staff then see "Suggested changes to review" in the panel.

Don't trust verification fields from the browser ​

is_verified, needs_review, verification_provider, verified_at and verification_metadata are fillable, so whatever a browser posts gets saved. Decide per form:

  • Signed-in staff or account forms (behind auth): accept them from the form. The values came from the API in the same session, and a user who forges them only affects their own records.
  • Public forms (checkout, sign-up): drop them before saving, then either let silent verification verify the address or call AddressResolver::verify() in the controller (one more paid call per save). With silent mode on, you can instead save the verification fields as the resolve/* or verify call returned them: the observer skips only a state the server produced in this session (the address with is_verified, needs_review and verification_provider) and verifies anything else. verified_at and verification_metadata aren't part of that check.
php
$data = $request->safe()->except([
    'is_verified', 'needs_review', 'verification_provider', 'verified_at', 'verification_metadata',
]);

Silent verification on save ​

With ADDRESS_VERIFICATION_MODE=silent, the package verifies every address when it's saved, whatever saved it: your controller, a job, an import, the Filament form. AddressVerificationObserver runs before the record is written and stores the result on it: standardized fields when verified, needs_review with the reason when not. Setup, guards and costs: Public Forms.

Know these before combining it with a custom form:

  • It doesn't verify twice. When AddressResolver (the Filament form, the HTTP API, your controller) verified an address in the current session, saving exactly that state doesn't call the provider again. The same holds for the user's own version after a choice ("keep mine": their fields, is_verified false, needs_review true), so it isn't replaced by the standardized one. The session holds a hash of those fields only (no provider or Google content), for an hour. Anything else is verified: a different address, verification fields the server didn't produce, saves without a session (queues, the console, an API stack without web). On updates, it runs only when an address field changed.

  • Saving outside a session. Server code that verified the address itself can skip the observer explicitly:

    php
    use Viewflex\FilamentAddress\Observers\AddressVerificationObserver;
    
    $address = AddressVerificationObserver::withoutVerification(
        fn () => $entity->addresses()->create($resolved->fields())
    );

    Never base that decision on values a browser posted.

  • Subdivision IDs. When it standardizes the state or city, the matching _id fields follow (matched with SubdivisionMatcher), and a district is matched again under a new city. If the provider's city matches no subdivision, the user's city and its ID are kept.

  • The panel has its own mode. ADDRESS_FILAMENT_VERIFICATION_MODE sets the admin form's mode; unset, it follows ADDRESS_VERIFICATION_MODE. With the global mode silent and the panel interactive, every save is verified while staff keep the Verify button and the comparison dialog, and an address verified in the form is saved without a second call.

Places Autocomplete in your own form ​

The Filament form's search box is Google's PlaceAutocompleteElement. To offer the same in your own form, load the Maps JavaScript API with the browser key (config('addresses.google_maps_browser_key'), from GOOGLE_MAPS_BROWSER_KEY) and send the selection to resolve/place, as the package's address-search-field.js does:

js
const { PlaceAutocompleteElement } = await google.maps.importLibrary('places');

const autocomplete = new PlaceAutocompleteElement();
autocomplete.includedRegionCodes = [countryCode.toLowerCase()];   // before adding it to the page
container.appendChild(autocomplete);

autocomplete.addEventListener('gmp-select', async ({ placePrediction }) => {
    const typed = autocomplete.value || '';                         // read before fetchFields()
    const place = placePrediction.toPlace();

    await place.fetchFields({
        fields: ['addressComponents', 'formattedAddress', 'location', 'displayName', 'id', 'primaryType'],
    });
    if (! place.location) return;

    const component = (type, short = false) => {
        const c = (place.addressComponents || []).find((c) => c.types.includes(type));
        return c ? (short ? c.shortText : c.longText) : '';
    };

    const placeCountry = component('country', true);
    if (placeCountry && placeCountry.toLowerCase() !== countryCode.toLowerCase()) {
        return;   // includedRegionCodes is a preference, not a filter: refuse other countries
    }

    // Google often leaves the house number out of the components (CN, JP, KR, partial
    // matches); take it from what the user typed
    let number = component('street_number');
    const route = component('route');
    const typedNumber = typed.match(/^(?:No\.?\s*)?(\d+[A-Za-z]?)\s+/i);
    if (! number && route && typedNumber) number = typedNumber[1];

    const { data } = await axios.post('/address-api/resolve/place', {
        place_id: place.id,
        name: place.displayName || place.formattedAddress,
        street_address: number && route ? `${number} ${route}` : route,
        postal_code: component('postal_code'),
        country_code: placeCountry,
        formatted_address: place.formattedAddress,
        primary_type: place.primaryType || '',
        lat: place.location.lat(),
        lng: place.location.lng(),
        current: { country_code: countryCode },
    });
    // data is a ResolvedAddress record, as for resolve/input
});
  • Billing. The element manages the session token: suggestions while typing are free in a completed session, and the fetchFields() call at the end is billed. Google prices that lookup by the fields requested; the list above matches the package's (see the FAQ). resolve/place then geocodes the place ID on the server for the stored coordinates (one Geocoding call).
  • Google's terms. Nothing from Google may be cached, so don't store autocomplete results in the browser beyond the form. Google place and geocoding data may only be shown on a Google map: for a map preview, use the package's static map proxy (<img src="/filament-address/map-image?lat=…&lng=…">, see Configuration), not a Leaflet or Mapbox map.

Reviewing flagged addresses ​

Addresses that need attention have needs_review set and the reasons in verification_metadata.review_reasons (Review reasons): a rejected address, an approximate location, a missing apartment number, the user keeping their version over the standardized one.

  • In the admin panel, the Addresses table shows the amber badge with the reasons in its tooltip and can be filtered by review status; opening a record shows the reasons in the badge popover, with Verify and Accept Address. See Admin Panel. The panel works the same whether the address came from the Filament form, your own form or an import.
  • In your own UI, ReviewStatus::of($address) gives the same explanation (headline(), messages(), codes()), and Address::where('needs_review', true) finds the records.
  • Bulk jobs (import, bulk verification) fire events when they finish, with counts of flagged addresses, for notifying staff without Filament.

Released under a commercial license.