Filament Api
Without using the sushi package, is there another way to use an api with Filament? Would anyone have an example to help me?
6 Replies
why not sushi?
@Leandro FerreiraHi Leandro, due to an error that I cannot resolve in Suchi a simple array, as in the documentation, everything is fine, but when I have an array within arrays it returns an error Array to string conversion,Do you have any idea what it could be? I appreciate your help
[▼
"numeroContrato" => "10004154-0"
"ativo" => true
"dataCriacao" => "2023-11-23T17:50:31.000+00:00"
"dataAtualizacao" => null
"id" => "1b8759b8"
"contratoItem" => array:2 [▶]
"usuarioCriacao" => "10914"
"usuarioAtualizacao" => null
"propostas" => array:103 [▶]
"contratoAtualizacaoCci" => null
]
debugging the model returns this object but cannot pass it to the filament table
contratoItem and propostas this causing array to string error
Hum, I didn't try it with subitems.. but I will recommend two articles
https://laraveldaily.com/post/filament-load-table-data-from-3rd-party-api
https://filamentphp.com/community/how-to-consume-an-external-api-with-filament-tables
Laravel Daily
Filament: Load Table Data From 3rd Party API
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.
Well, I had read these 2 articles before too and used your article as a basis but without success. It wasn't a problem with Sushi, it seems that he can't read the propostaarrays
hum not sure about subitems
Maybe you can share an example on github to reproduce the behavior.. I can take a look
Sorry, I'm new and I'm not using github, can I give you the model and data array here?
this would be the model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;
use Illuminate\Support\Arr;
use App\Facades\ApiConciliadorFacades;
class ContratoApi extends Model
{
use HasFactory;
use Sushi;
// protected $casts = [
// 'contratoItem' => 'json',
// 'propostas' => 'json',
// ];
// protected $schema = [
// 'contratoItem' => 'json',
// 'propostas' => 'json',
// ];
public function getRows()
{
//API $dados = ApiConciliadorFacades::ApiData()->get('/contrato')->json(); $dados = Arr::map($dados['data'], function ($item) { return Arr::only($item, [ 'id', 'numeroContrato', 'ativo', 'dataCriacao', 'dataAtualizacao', 'contratoItem',
'usuarioCriacao', 'usuarioAtualizacao', 'propostas',
'contratoAtualizacaoCci', ]); });
return $dados; }
} and this result [ "numeroContrato" => "10004154-0" "ativo" => true "dataCriacao" => "2023-11-23T17:50:31.000+00:00" "dataAtualizacao" => null "id" => "1b8759b8" "contratoItem" => ['id' => '10154'] "usuarioCriacao" => "10914" "usuarioAtualizacao" => null "propostas" => ['id' => '25', 'name' => 'Marcos Viega','proposta_id' => '25987457'] "contratoAtualizacaoCci" => null ] contratoItem or Proposta generates the error
//API $dados = ApiConciliadorFacades::ApiData()->get('/contrato')->json(); $dados = Arr::map($dados['data'], function ($item) { return Arr::only($item, [ 'id', 'numeroContrato', 'ativo', 'dataCriacao', 'dataAtualizacao', 'contratoItem',
'usuarioCriacao', 'usuarioAtualizacao', 'propostas',
'contratoAtualizacaoCci', ]); });
return $dados; }
} and this result [ "numeroContrato" => "10004154-0" "ativo" => true "dataCriacao" => "2023-11-23T17:50:31.000+00:00" "dataAtualizacao" => null "id" => "1b8759b8" "contratoItem" => ['id' => '10154'] "usuarioCriacao" => "10914" "usuarioAtualizacao" => null "propostas" => ['id' => '25', 'name' => 'Marcos Viega','proposta_id' => '25987457'] "contratoAtualizacaoCci" => null ] contratoItem or Proposta generates the error