0

I want to ask a question about Laravel Filament Table.

I have a model which has a column with array. I want to visualize that array column with Filament query builder.

My Model Column is like;

[
  'name' => 'result',
  'name2' => 'result2'
]

My Livewire Component with Table builder

<?php

namespace App\Http\Livewire\UptimeChecker;

use App\Models\UptimeChecker\Check;
use Faker\Provider\Text;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Filters\Filter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Livewire\Component;

class ListCheckResult extends Component implements HasTable
{
    use InteractsWithTable;

    public Check $record;

    public function render()
    {
        return view('livewire.uptime-checker.list-check-result');
    }

    protected function getTableQuery(): Builder|Relation
    {
        return $this->record->query()->where('id', '=', $this->record->id);
    }

    protected function getTableColumns(): array
    {
        return [
            TextColumn::make('Name')
                ->getStateUsing(fn($record) => array_keys($record->result)),
            TextColumn::make('Result')
                ->getStateUsing(fn($record) => array_values($record->result))
        ];
    }
}

I am expecting a table with two columns which have Name and Result from Model Array Column.

How can i build columns? Of course if I can. Thank you for replies and sorry for bad grammar.

Mahodroid
  • 43
  • 7

1 Answers1

0

Shortly, I could not and should not do that.

Filament Table Builder looking query for creating columns and you can not create column list for another object|array.

I created another blade view for showing record result array.

Mahodroid
  • 43
  • 7