F
Filament8mo ago
Lucky0

External API CRUD in Filament

I am using "https://github.com/kawax/laravel-google-sheets" and "https://github.com/calebporzio/sushi". At the moment I can fetch the data from google sheets. I followed these two source "https://laraveldaily.com/post/filament-load-table-data-from-3rd-party-api" and "https://filamentphp.com/community/how-to-consume-an-external-api-with-filament-tables". I could not find any other reference for update, create and delete. Is it possible to do this in filament? do I need to create custom livewire class? currently I have this for retrieving the data from google sheets
namespace App\Models\Sheets;

use Revolution\Google\Sheets\Facades\Sheets;
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;

class User extends Model
{
use Sushi;

protected $guarded = [
'id',
];

public function getRows(): array
{
$rows = Sheets::spreadsheet(config('google.sheets_api'))->sheet('sheet1')->get();

$header = $rows->pull(0);
$values = Sheets::collection(header: $header, rows: $rows);

$data = array_values($values->map(function ($row) {
return collect($row)->mapWithKeys(function ($value, $key) {
if (in_array($key, ['id', 'age'])) {
return [$key => intval($value)];
}
return [$key => $value];
});
})->toArray());

return $data;
}

}
namespace App\Models\Sheets;

use Revolution\Google\Sheets\Facades\Sheets;
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;

class User extends Model
{
use Sushi;

protected $guarded = [
'id',
];

public function getRows(): array
{
$rows = Sheets::spreadsheet(config('google.sheets_api'))->sheet('sheet1')->get();

$header = $rows->pull(0);
$values = Sheets::collection(header: $header, rows: $rows);

$data = array_values($values->map(function ($row) {
return collect($row)->mapWithKeys(function ($value, $key) {
if (in_array($key, ['id', 'age'])) {
return [$key => intval($value)];
}
return [$key => $value];
});
})->toArray());

return $data;
}

}
6 Replies
toeknee
toeknee8mo ago
You cannot create from Sushi only read. If you wish to create, you'll need to build your own form and store it with your own method.
Lucky0
Lucky0OP8mo ago
I see. thank you
kool
kool8mo ago
It is not possible as filament fully relies in eloquent model and sushi just can provide you way to read or populate data but it comes with a lot of limitations & challenges when it comes table capabilities (sorting, filtering, so on, also create/update/delete) etc. I recommend that you implement your own livewire component and integrate with filament tables, forms, actions or what ever you need. - https://filamentphp.com/docs/3.x/tables/adding-a-table-to-a-livewire-component - https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component - https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component
kool
kool8mo ago
You just need to learn the livewire fundamentals from the docs and you start truly from there. -------------------------------------------------- Aside, you check this discussion if it helps
kool
kool8mo ago
GitHub
Building Custom Table From API Data source and interact with API · ...
I want to create a custom page in Filament but do not want to use Filaments table builder. I just want to use the Filament table's HTML and style so that the admin panel has a similar design. I...
kool
kool8mo ago
Want results from more Discord servers?
Add your server