Documentation Index
Fetch the complete documentation index at: https://mintlify.com/diegobas/filament-drawable-map/llms.txt
Use this file to discover all available pages before exploring further.
DrawableMap represents polygon zones as a flat array of latitude/longitude pairs. Understanding how coordinates flow between the map component, your Eloquent model, and the database will help you set up migrations correctly, avoid double-encoding bugs, and query or transform zone data with confidence.
Coordinate Format
Every polygon is stored as a JSON array of objects, each containing alat key and a lng key. The array is ordered — vertices are connected in sequence, and the polygon is automatically closed by Google Maps.
Database Migration
The column that stores the polygon must be ajson type. A nullable constraint is recommended because a field can be saved before any zone has been drawn.
Model Cast
Cast thezone column to array in your Eloquent model so that Laravel automatically handles JSON encoding and decoding on read/write:
zone is cast to array, Eloquent returns the column value as a PHP array. DrawableMap is aware of this and handles the encoding boundary through two lifecycle hooks:
callAfterStateHydrated()— when the form is loaded, if the state is already a string (e.g. raw JSON from a non-cast column), the component JSON-decodes it into an array before passing it to the Alpine component.getStateToDehydrate()— before the state is written back to the model, if the state has become a JSON string (fromgetState()encoding it for Alpine), the component JSON-decodes it again so Eloquent receives a plain array and applies its own cast correctly.
How Serialization Works
The serialization lifecycle has three stages:State sent to Alpine (getState)
DrawableMap::getState() checks whether the current state is an array. If it is, the method JSON-encodes it to a string so the value can be embedded safely in the Alpine x-data attribute as state.State loaded from model (callAfterStateHydrated)
After Filament hydrates the field from the model record,
callAfterStateHydrated() checks whether the state is a string. If so, it JSON-decodes it back to an array and calls $this->state($decoded) so the component holds a clean PHP array internally.State written back to model (getStateToDehydrate)
When the form is submitted,
getStateToDehydrate() intercepts the state array before it is written to the model. If the value is a JSON string at that point, it is decoded back to an array so that Eloquent’s array cast receives the correct type and stores valid JSON in the database column.array or json.
Reading Data Back
Once a zone has been saved you can work with it as an ordinary PHP array:'lat' and 'lng' keys. Standard PHP array functions — array_column, array_map, array_filter, and so on — work directly against this structure.