F
Filament4mo ago
xdm412

V4 Custom Page with Custom Data Table

Hey all, I'm working on a project where I'm trying to use the V4 beta of Filament to display a table based on API data. I'm running into some issues where it looks to be trying to load relations from the response collection even though the items are not models and its not associated with a resource. Here is my custom page / table implementation:
<?php

declare(strict_types=1);

namespace App\Filament\Pages;

use App\Actions\People\ListPeople as ListPeopleAction;
use BackedEnum;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;
use Illuminate\Support\Collection;

class ListPeople extends Page implements HasTable
{
use InteractsWithTable;

protected string $view = 'filament.pages.list-people';

protected static ?string $slug = 'people';

protected static string|null|BackedEnum $navigationIcon = Heroicon::OutlinedUsers;

protected static ?string $navigationLabel = 'People';

protected static ?string $title = 'People';

public function table(Table $table): Table
{
return $table
->records(function (
int $page,
int $recordsPerPage,
): Collection {
return ListPeopleAction::make()->handle(
asUser: auth()->user(),
page: $page,
recordsPerPage: $recordsPerPage,
)->collect('data.people')
->pluck('person', 'person.uuid');
})
->columns([
TextColumn::make('uuid'),
TextColumn::make('first_name'),
TextColumn::make('last_name'),
TextColumn::make('email'),
TextColumn::make('phone'),
TextColumn::make('created_at'),
]);
}
}
<?php

declare(strict_types=1);

namespace App\Filament\Pages;

use App\Actions\People\ListPeople as ListPeopleAction;
use BackedEnum;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Table;
use Illuminate\Support\Collection;

class ListPeople extends Page implements HasTable
{
use InteractsWithTable;

protected string $view = 'filament.pages.list-people';

protected static ?string $slug = 'people';

protected static string|null|BackedEnum $navigationIcon = Heroicon::OutlinedUsers;

protected static ?string $navigationLabel = 'People';

protected static ?string $title = 'People';

public function table(Table $table): Table
{
return $table
->records(function (
int $page,
int $recordsPerPage,
): Collection {
return ListPeopleAction::make()->handle(
asUser: auth()->user(),
page: $page,
recordsPerPage: $recordsPerPage,
)->collect('data.people')
->pluck('person', 'person.uuid');
})
->columns([
TextColumn::make('uuid'),
TextColumn::make('first_name'),
TextColumn::make('last_name'),
TextColumn::make('email'),
TextColumn::make('phone'),
TextColumn::make('created_at'),
]);
}
}
No description
Solution:
Actually I just figured this out... if any field that is returned is null, it tries to find it via a relationship. My workaround for this is to set the state to an empty string.
No description
Jump to solution
3 Replies
xdm412
xdm412OP4mo ago
My first thought here is that I'm using the wrong interface / implementation but the docs are a bit scarce around the custom data section and only provide the table() method and not the surrounding class. The view looks like this:
<x-filament-panels::page>
{{ $this->table }}
</x-filament-panels::page>
<x-filament-panels::page>
{{ $this->table }}
</x-filament-panels::page>
Solution
xdm412
xdm4124mo ago
Actually I just figured this out... if any field that is returned is null, it tries to find it via a relationship. My workaround for this is to set the state to an empty string.
No description
xdm412
xdm412OP4mo ago
I'll create a bug ticket for these cases if this isn't intended behaviour.

Did you find this page helpful?