Laravel filament v3 sushi

Array to string conversion any idea to resolve this?
4 Replies
Dennis Koch
Dennis Koch13mo ago
Sounds like your data doesn’t match your schema. But without any info it’s hard to tell
Carlos Lopes
Carlos LopesOP13mo ago
Hi Dennis, my model is configured this way <?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; public function getRows() {
//API $dados = ApiConciliadorFacades::ApiData()->get('/contrato')->json(); //filtering some attributes $dados = Arr::map($dados['data'], function ($item) {
return Arr::only($item, [ 'id', 'numeroContrato', 'ativo', 'dataCriacao', 'dataAtualizacao', 'contratoItem', 'usuarioCriacao', 'usuarioAtualizacao', 'propostas', 'contratoAtualizacaoCci', ] ); });
return $dados; } } and its result is this array:10 [▼ // app\Models\ContratoApi.php:45 "numeroContrato" => "10004154-0" "ativo" => true "dataCriacao" => "2023-11-23T17:50:31.000+00:00" "dataAtualizacao" => null "id" => "1b8759b8" "contratoItem" => array:1 [▶] "usuarioCriacao" => "10914" "usuarioAtualizacao" => null "propostas" => array:103 [▶] "contratoAtualizacaoCci" => null ] in my resource table have return this Array to string conversion
Matthew
Matthew13mo ago
The "Array to string conversion" error suggests that sushi expexts the getRows() function to return an array of arrays In your code, the fields "contratoItem" and "propostas" appear to be arrays, but they need to be scalar values like int,bool, etc.. Imo thats what causing the issue. Try encoding them into json, and see what you get
$dados = Arr::map($dados['data'], function ($item) {
$item['contratoItem'] = json_encode($item['contratoItem']);
$item['propostas'] = json_encode($item['propostas']);

return Arr::only($item, [
'id',
'numeroContrato',
'ativo',
'dataCriacao',
'dataAtualizacao',
'contratoItem', // Now the column is JSON string
'usuarioCriacao',
'usuarioAtualizacao',
'propostas', // Now the column is JSON string
'contratoAtualizacaoCci',
]);
});
$dados = Arr::map($dados['data'], function ($item) {
$item['contratoItem'] = json_encode($item['contratoItem']);
$item['propostas'] = json_encode($item['propostas']);

return Arr::only($item, [
'id',
'numeroContrato',
'ativo',
'dataCriacao',
'dataAtualizacao',
'contratoItem', // Now the column is JSON string
'usuarioCriacao',
'usuarioAtualizacao',
'propostas', // Now the column is JSON string
'contratoAtualizacaoCci',
]);
});
Carlos Lopes
Carlos LopesOP13mo ago
@Matthew same error, if I remove these two fields it can read the data but there is data within these arrays that I also need to recover
Want results from more Discord servers?
Add your server