F
Filament11mo ago
Marc

Show data that does not come from the DB

How could I show data on the edit or view screen that does not come from the database, for example, from an API, or IP data through Geoip. You would also have to have access to the model to obtain its data to be able to make the query.
11 Replies
Marc
MarcOP11mo ago
I have seen that there is a package called sushi, but in my case it does not work, what I want to do is, for example: When you edit or view a user, have all the user's data obtained from the DB and in a new section, given the IP, country, city... To get the IP data, you would have to get the model's ip field, do the search to get all the data for that IP, and then display it in different fields.
Tim van Heugten
Tim van Heugten11mo ago
Filament
Search & load form data from an API by Z3d0X - Tricks - Filament
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
Filament
Geocoding field using Select component by Dennis Koch - Tricks - Fi...
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
Marc
MarcOP11mo ago
I've mentioned it before, sushi doesn't work for me.
krekas
krekas11mo ago
then forget it or make it work
Marc
MarcOP11mo ago
These examples are for input components, I only want to show information, which cannot be updated or anything, just view
Tim van Heugten
Tim van Heugten11mo ago
As you mentioned the edit page I thought inputs were involved You can show data in disabled / non editable input fields (nicely gathered in a section or fieldset for example). Fetching the external data can happen on some click or pageload. If the 3rd party data doesn’t change often consider fetching and storing it.
krekas
krekas11mo ago
if it's only one page create a custom page and fetch data there otherwise pages for now needs to have eloquent query
Marc
MarcOP11mo ago
By doing tests, I have found a way to display data, but I don't know if it is the most correct or if there is some component that does not require a query to work.
$form->schema(function () {
return [
'left' => Section::make([
//...
])->columnSpan(8),

'right' => Section::make([
Placeholder::make('ip')
->label('Country')
->content(function (string $state): string {
//GeoIp - Search and cache IP data if any other component needs to search for the same IP
return GeoIp::find($state)?->country?->names['en'] ?? new HtmlString('—');
}),
//more Placeholders
])->columnSpan(4),
];
})
$form->schema(function () {
return [
'left' => Section::make([
//...
])->columnSpan(8),

'right' => Section::make([
Placeholder::make('ip')
->label('Country')
->content(function (string $state): string {
//GeoIp - Search and cache IP data if any other component needs to search for the same IP
return GeoIp::find($state)?->country?->names['en'] ?? new HtmlString('—');
}),
//more Placeholders
])->columnSpan(4),
];
})
krekas
krekas11mo ago
if it's just for this one field then this is the way
Marc
MarcOP11mo ago
From GeoIp you can obtain accuracy radius, Latitude/Longitude, continent, country, subdivisions, city, postal code, currency, therefore, I would have to create a placeholder for each one and I don't know if there is any way for state to receive all this data , instead of having to access GeoIp on each Placeholder If it is not possible, I will have to make more logic in GeoIp so that instead of every time find is called it searches for the data within a database, it saves it in a variable so that it is faster when other placeholders call it
Want results from more Discord servers?
Add your server