How to handle data from an external api in a filament table

Does filament allow showing of data that is from an external api in the table
24 Replies
toeknee
toeknee2mo ago
One of the most asked questions...... use sushi
toeknee
toeknee2mo ago
Filament
How to consume an external API with Filament Tables by Leandro Ferr...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
codeartisan
codeartisan2mo ago
Thank you sir @toeknee I think this solution does not work when am using just a filament table in laravel because thats what am doing currently Do you think you have any alternative?
toeknee
toeknee2mo ago
Yes yes it does, it's exactly what it says....
codeartisan
codeartisan2mo ago
It was a typo I am using the filament table component in livewire but I need to fetch some data from an external api then feed it into the table but it seems that package works only with filament admin
toeknee
toeknee2mo ago
That package has nothing to do with filament admin. It uses models and is completely independent of filament.
codeartisan
codeartisan2mo ago
okay let me review it again php artisan make:model Product php artisan make:filament-resource Product --simple --view Here it need me to create filament resource @toeknee it requires me to create a filament resource
Dennis Koch
Dennis Koch2mo ago
Well, the tutorial is for the admin panel, but you don't need to strictly follow it. You can also create a Filament table in a Livewire component
codeartisan
codeartisan2mo ago
I have the table already created
Dennis Koch
Dennis Koch2mo ago
No need to create a resource then
codeartisan
codeartisan2mo ago
Tested it and it renders but it picks from a model i want to fetch data from an external @toeknee had recommended that
Dennis Koch
Dennis Koch2mo ago
So what did you do? Did you follow the rest of the tutorial?
codeartisan
codeartisan2mo ago
Yeah i went through but failed to figure out how to pick the data from the model to the table
Dennis Koch
Dennis Koch2mo ago
So what's your model code?
codeartisan
codeartisan2mo ago
let me share
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Arr;

class Station extends Model
{
use HasFactory, Sushi;

//{"Code":"SUG-001","Name":"kirinya","LocationType":" ","email":"","phoneNumber":"","latitude":"","longitude":""}

protected $fillable = ['Code','Name','LocationType','email','phoneNumber','latitude','longitude'];

/**
* Model Rows
*
* @return void
*/
public function getRows()
{
//API
$stations = Http::get('https://graph.stabexinternational.com/api/stations/getLocations')->json();

//filtering some attributes
$stations = Arr::map($stations['data'], function ($item) {
return Arr::only($item,
[
'Code',
'Name',
'LocationType',
'email',
'PhoneNumber',
'latitude',
'longitude',

]
);
});

return $stations;
}

}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Arr;

class Station extends Model
{
use HasFactory, Sushi;

//{"Code":"SUG-001","Name":"kirinya","LocationType":" ","email":"","phoneNumber":"","latitude":"","longitude":""}

protected $fillable = ['Code','Name','LocationType','email','phoneNumber','latitude','longitude'];

/**
* Model Rows
*
* @return void
*/
public function getRows()
{
//API
$stations = Http::get('https://graph.stabexinternational.com/api/stations/getLocations')->json();

//filtering some attributes
$stations = Arr::map($stations['data'], function ($item) {
return Arr::only($item,
[
'Code',
'Name',
'LocationType',
'email',
'PhoneNumber',
'latitude',
'longitude',

]
);
});

return $stations;
}

}
Want results from more Discord servers?
Add your server