© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
5 replies
fsamapoor

How to test Counting relationships

I'm counting the number of related records in a text column based on the documentation and everything works fine.

Tables\Columns\TextColumn::make('messages_count')
    ->counts('messages'),
Tables\Columns\TextColumn::make('messages_count')
    ->counts('messages'),


How can I test the relationship count with Pest? I tried to test it by chaining
assertTableColumnStateSet
assertTableColumnStateSet
method to the table component, but no luck so far.

Please tell me if I should provide any further details.

The error:

Failed asserting that a table column with name [messages_count] has value of [1] for record [1] on the [App\Filament\Resources\TelegramUserResource\Pages\ListTelegramUsers] component.
Failed asserting that a table column with name [messages_count] has value of [1] for record [1] on the [App\Filament\Resources\TelegramUserResource\Pages\ListTelegramUsers] component.


The test:

it('can show the messages count in the table.', function () {
    $message = Message::factory()
        ->has(TelegramUser::factory(), 'telegram_user')
        ->create();

    $telegram_user = $message->telegram_user;

    livewire(TelegramUserResource\Pages\ListTelegramUsers::class)
        ->assertTableColumnStateSet(
            name: 'messages_count',
            value: 1,
            record: $telegram_user,
        );
});
it('can show the messages count in the table.', function () {
    $message = Message::factory()
        ->has(TelegramUser::factory(), 'telegram_user')
        ->create();

    $telegram_user = $message->telegram_user;

    livewire(TelegramUserResource\Pages\ListTelegramUsers::class)
        ->assertTableColumnStateSet(
            name: 'messages_count',
            value: 1,
            record: $telegram_user,
        );
});
Solution
Not sure, but try using the record ID instead:
record: $telegram_user->id,
record: $telegram_user->id,
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Counting relationships
FilamentFFilament / ❓┊help
2y ago
Counting relationships performance
FilamentFFilament / ❓┊help
3y ago
relationships counting-relationships with date filters
FilamentFFilament / ❓┊help
2y ago
How do I test the Managing relationships form
FilamentFFilament / ❓┊help
2y ago