adesege
adesege
FFilament
Created by adesege on 3/6/2024 in #❓┊help
Action opening an empty state modal
No description
2 replies
FFilament
Created by adesege on 1/21/2024 in #❓┊help
Pass data from getSearchResultsUsing to afterStateUpdated
Hi, How can I pass data from getSearchResultsUsing to afterStateUpdated? The idea is to "cache" $result in getSearchResultsUsing so I can reuse it in afterStateUpdated to avoid reruning the geocode query. I tried declaring a variable in the Page class then set the value in getSearchResultsUsing but that didn't work.
Forms\Components\Select::make('geocoding')
->label('Search')
->searchable()
->reactive()
->dehydrated(false)
->getSearchResultsUsing(function ($query) {
return app('geocoder')->geocode($query)->get()
->mapWithKeys(fn ($result) => [
$result->getFormattedAddress() => $result->getFormattedAddress()
])
->toArray();
})
->afterStateUpdated(function ($state, $set) {
/** @var \Geocoder\Provider\GoogleMaps\Model\GoogleAddress $result */
$result = app('geocoder')->geocode($state)->get()->first();
$coords = $result->getCoordinates();

$set('street', $result->getStreetName());
$set('street_number', $result->getStreetNumber());
$set('city', $result->getLocality());
$set('zipcode', $result->getPostalCode());
$set('latitude', $coords->getLatitude());
$set('longitude', $coords->getLongitude());
}),
Forms\Components\Select::make('geocoding')
->label('Search')
->searchable()
->reactive()
->dehydrated(false)
->getSearchResultsUsing(function ($query) {
return app('geocoder')->geocode($query)->get()
->mapWithKeys(fn ($result) => [
$result->getFormattedAddress() => $result->getFormattedAddress()
])
->toArray();
})
->afterStateUpdated(function ($state, $set) {
/** @var \Geocoder\Provider\GoogleMaps\Model\GoogleAddress $result */
$result = app('geocoder')->geocode($state)->get()->first();
$coords = $result->getCoordinates();

$set('street', $result->getStreetName());
$set('street_number', $result->getStreetNumber());
$set('city', $result->getLocality());
$set('zipcode', $result->getPostalCode());
$set('latitude', $coords->getLatitude());
$set('longitude', $coords->getLongitude());
}),
Thanks
1 replies