How to show results of an API in custom page table builder.
I've created a custom page in which I request to a URL with cURL to get an API and I want to show the results in the table builder on my custom page. How can I do that?
22 Replies
You can use this awesome plugin
https://filamentphp.com/plugins/drop-in-action
Filament
Drop-In Action by Adam Weston - Plugins - Filament
A form component for Filament to integrate actions into forms.
I don't want to have any form on my custom page I just want to have a table from the API result.
On mount get data from api and fill the form
Could you show us your code ?
I think I found an article that might help me https://filamentphp.com/blog/how-to-consume-an-external-api-with-filament-tables
Filament
How to consume an external API with Filament Tables by Leandro C. F...
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
it's just a basic livewire + laravel code to get your data from api
Yes but the problem is in a custom page that implements
HasTable
I should return a Builder
type object from getTableQuery
method to show that in a table, that means it should be read from a database although I don't have any database for it and as a result it throws an error saying the result from that URL isn't of type Builder
return an empty query IIRC, or 'products' as an example... But Sushi should work fine.
Great article! The call used in the example get all records. Do you know the best way to retreive external records from an API with records limit / pagination? I have an API with 10k records with a limit of 100 records max.
Just keep a counter and loop through? You can even use a throttle to limit the amount of calls per minute if the api is that restrictive
The goal will be to match the filament table pagination and offset and trigger API call like this one: https://pokeapi.co/api/v2/pokemon/?limit=100&offset=300
I have the total records and the total pages from the API as well
So you don't want to consume, you want to integrate right?
this is only to consume, read only but the data is changing and growing, like an order list
I have the lead of a filament resource + sushi but not sure if I should start with this or make a custom page with table
That should suffice, just disable the edit/delete links and the create action in the list page
Thanks, but I am no sure to understand how to get the filament page and pass it to the external api 🤷🏼♂️
So you are wanting to render this outside of filament? If so then a custom page with tables and sushi is needed
@toeknee_iom thanks for your support, I made some progress but not sure if is the right way to achieve it: To resume, I would like the same behaviour of the article. But the external API I am using limits the max records I can get on a call. So what I have done so far is a Sushi Model with a static method
params
which allows me to setup two static properties ( $page and $recordsPerPage ) and return an eloquent builder.
I overrided the getTableQuery
method to setup those params by returning:
return static::getResource()::getModel()::params($this->page, $this->tableRecordsPerPage);
then the getRows()
method of the model make a call with those params
now I can maybe add fake records to simulate the total number of records
Then, and this is the final step, I would need to override how the filament pagination works but I do not know how to do and if it makes senses or if there is another way.I’m not too sure myself tbh, does the sushi model not allow passing in a limit/page param
Not by default but you can:
`
I am making progress, I found a way to put the API result and display it on the selected filament page
Now I will play with filters and scopes
Thanks for your support!
Welcomes
@benzo Did you succeed in sending the resource pagination to the model?
I'm trying to do this here in the resource and I'm not succeeding.
I wanted to try a method that updates the query every time the pagination changes
im using filament v3
how urgent is it? V4 allows data from static data
https://github.com/filamentphp/filament/issues/7105
GitHub
Static tables · Issue #7105 · filamentphp/filament
Move table's Blade components to support and document their usage.